﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Xml;
using Common.Logging;
using In.Api.Dto.HisWs;
using In.Api.Helpers;
using InDbContext;
using Newtonsoft.Json;

namespace In.Api.Controllers
{
    public class HisWsController : ApiController
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(HisWsController));

        #region 获取医院介绍信息
        /// <summary>
        /// 获取医院介绍信息        
        /// </summary>
        [HttpPost]
        [ActionName("GetHospInfo")]
        public Response4GetHospInfo GetHospInfo(Request4GetHospInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = request.HospitalId;
            //root.AppendChild(hospitalIdNode);

            //XmlNode cardNoNode = xmlDoc.CreateElement("cardno");
            //cardNoNode.InnerText = request.CardNo;
            //root.AppendChild(cardNoNode);

            //XmlNode cardTypeNode = xmlDoc.CreateElement("cardtype");
            //cardTypeNode.InnerText = request.CardType;
            //root.AppendChild(cardTypeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetHosPatInfo();
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetHosPatInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetHosPatInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetHospInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.HospInfo = new Response4GetHospInfoSubHospInfo();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var hospInfoObj = new Response4GetHospInfoSubHospInfo();
                var hosPatId = xNode.SelectSingleNode("HosPatId").InnerText;
                var hosPatName = xNode.SelectSingleNode("HosPatName").InnerText;
                var shortName = xNode.SelectSingleNode("ShortName").InnerText;
                var address = xNode.SelectSingleNode("Address").InnerText;
                var tel = xNode.SelectSingleNode("Tel").InnerText;
                var webSite = xNode.SelectSingleNode("WebSite").InnerText;
                var level = xNode.SelectSingleNode("Level").InnerText;
                var desc = xNode.SelectSingleNode("Desc").InnerText;

                hospInfoObj.HospId = hosPatId;
                hospInfoObj.HospName = hosPatName;
                hospInfoObj.ShortName = shortName;
                hospInfoObj.Address = address;
                hospInfoObj.Tel = tel;
                hospInfoObj.WebSite = webSite;
                hospInfoObj.Level = level;
                hospInfoObj.Desc = desc;

                response.HospInfo = hospInfoObj;
            }

            return response;
        }
        #endregion

        #region 获取科室信息
        /// <summary>
        /// 获取科室信息        
        /// </summary>
        [HttpPost]
        [ActionName("GetDeptInfo")]
        public Response4GetDeptInfo GetDeptInfo(Request4GetDeptInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetDeptInfo();
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetDeptInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetDeptInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetDeptInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.DeptList = new List<Response4GetDeptInfoSubDeptInfo>();

            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var deptObj = new Response4GetDeptInfoSubDeptInfo();

                var deptName = xNode.SelectSingleNode("DeptName") == null ? "" : xNode.SelectSingleNode("DeptName").InnerText;
                var deptId = xNode.SelectSingleNode("DeptId") == null ? "" : xNode.SelectSingleNode("DeptId").InnerText;
                var loc = xNode.SelectSingleNode("Loc") == null ? "" : xNode.SelectSingleNode("Loc").InnerText;
                var deptType = xNode.SelectSingleNode("DeptType") == null ? "" : xNode.SelectSingleNode("DeptType").InnerText;
                var parentId = xNode.SelectSingleNode("ParentId") == null ? "" : xNode.SelectSingleNode("ParentId").InnerText;
                var desc = xNode.SelectSingleNode("Desc") == null ? "" : xNode.SelectSingleNode("Desc").InnerText;

                deptObj.DeptId = deptId;
                deptObj.DeptName = deptName;
                deptObj.Loc = loc;
                deptObj.DeptType = deptType;
                deptObj.ParentId = parentId;
                deptObj.Desc = desc;

                response.DeptList.Add(deptObj);
            }

            return response;
        }

        #endregion

        #region 获取医生信息
        /// <summary>
        /// 获取医生信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetDoctorInfo")]
        public Response4GetDoctorInfo GetDoctorInfo(Request4GetDoctorInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("DocId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetDocInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetDocInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetDocInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetDoctorInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.DoctorList = new List<Response4GetDoctorInfoSubDoctorInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var doctorInfoObj = new Response4GetDoctorInfoSubDoctorInfo();
                var doctorId = xNode.SelectSingleNode("DocId") == null ? "" : xNode.SelectSingleNode("DocId").InnerText;
                var doctorName = xNode.SelectSingleNode("DocName") == null ? "" : xNode.SelectSingleNode("DocName").InnerText;
                var deptId = xNode.SelectSingleNode("DeptId") == null ? "" : xNode.SelectSingleNode("DeptId").InnerText;
                var deptName = xNode.SelectSingleNode("DeptName") == null ? "" : xNode.SelectSingleNode("DeptName").InnerText;
                var title = xNode.SelectSingleNode("DocWork") == null ? "" : xNode.SelectSingleNode("DocWork").InnerText;
                var gender = xNode.SelectSingleNode("DocSex") == null ? "" : xNode.SelectSingleNode("DocSex").InnerText;
                var desc = xNode.SelectSingleNode("Desc") == null ? "" : xNode.SelectSingleNode("Desc").InnerText;

                doctorInfoObj.DoctorId = doctorId;
                doctorInfoObj.DoctorName = doctorName;
                doctorInfoObj.DeptId = deptId;
                doctorInfoObj.DeptName = deptName;
                doctorInfoObj.Title = title;
                doctorInfoObj.Gender = gender;
                doctorInfoObj.Desc = desc;

                response.DoctorList.Add(doctorInfoObj);
            }
            return response;
        }

        #endregion

        #region 获取可挂号科室列表
        /// <summary>
        /// 获取允许挂号的科室列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetRegDeptList")]
        public Response4GetRegDeptList GetRegDeptList(Request4GetRegDeptList request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetRegDeptList();
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetRegDeptList 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetRegDeptList", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetRegDeptList();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;


            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.RegDeptList = new List<Response4GetRegDeptListSubRegDeptInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var regDeptObj = new Response4GetRegDeptListSubRegDeptInfo();

                var deptId = xNode.SelectSingleNode("DeptId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptId".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var waitCount = xNode.SelectSingleNode("WaitCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitCount".ToUpper()).InnerText;
                var regCount = xNode.SelectSingleNode("RegCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegCount".ToUpper()).InnerText;
                var regLimit = xNode.SelectSingleNode("RegLimit".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegLimit".ToUpper()).InnerText;
                var regAmt = xNode.SelectSingleNode("RegAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegAmt".ToUpper()).InnerText;
                var regType = xNode.SelectSingleNode("RegType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegType".ToUpper()).InnerText;
                var startTime = xNode.SelectSingleNode("StartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("StartTime".ToUpper()).InnerText;
                var endTime = xNode.SelectSingleNode("EndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("EndTime".ToUpper()).InnerText;

                regDeptObj.DeptId = deptId;
                regDeptObj.DeptName = deptName;
                regDeptObj.WaitCount = waitCount;
                regDeptObj.RegCount = regCount;
                regDeptObj.RegLimit = regLimit;
                regDeptObj.RegAmt = regAmt;
                regDeptObj.RegType = regType;
                regDeptObj.StartTime = startTime;
                regDeptObj.EndTime = endTime;
                regDeptObj.StartTime = startTime;
                regDeptObj.EndTime = endTime;

                response.RegDeptList.Add(regDeptObj);
            }

            return response;
        }

        #endregion

        #region 获取可挂号医生列表
        /// <summary>
        /// 获取可挂号医生列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetRegDoctorList")]
        public Response4GetRegDoctorList GetRegDoctorList(Request4GetRegDoctorList request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetRegDocList(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetRegDocList 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetRegDocList", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetRegDoctorList();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.RegDoctorList = new List<Response4GetRegDoctorListSubRegDoctorInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var regDoctorObj = new Response4GetRegDoctorListSubRegDoctorInfo();

                var scheduleId = xNode.SelectSingleNode("ScheduleId".ToUpper()) == null ? "" : xNode.SelectSingleNode("ScheduleId".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var subjectId = xNode.SelectSingleNode("SubjectId".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectId".ToUpper()).InnerText;
                var subjectName = xNode.SelectSingleNode("SubjectName".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectName".ToUpper()).InnerText;
                var waitCount = xNode.SelectSingleNode("WaitCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitCount".ToUpper()).InnerText;
                var regCount = xNode.SelectSingleNode("RegCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegCount".ToUpper()).InnerText;
                var regLimit = xNode.SelectSingleNode("RegLimit".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegLimit".ToUpper()).InnerText;
                var regType = xNode.SelectSingleNode("RegType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegType".ToUpper()).InnerText;
                var regAmt = xNode.SelectSingleNode("RegAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegAmt".ToUpper()).InnerText;
                var startTime = xNode.SelectSingleNode("StartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("StartTime".ToUpper()).InnerText;
                var endTime = xNode.SelectSingleNode("EndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("EndTime".ToUpper()).InnerText;
                var state = xNode.SelectSingleNode("State".ToUpper()) == null ? "" : xNode.SelectSingleNode("State".ToUpper()).InnerText;

                regDoctorObj.ScheduleId = scheduleId;
                regDoctorObj.DoctorId = docId;
                regDoctorObj.DoctorName = docName;
                regDoctorObj.SubjectId = subjectId;
                regDoctorObj.SubjectName = subjectName;
                regDoctorObj.WaitCount = waitCount;
                regDoctorObj.RegCount = regCount;
                regDoctorObj.RegLimit = regLimit;
                regDoctorObj.RegType = regType;
                regDoctorObj.RegAmt = regAmt;
                regDoctorObj.StartTime = startTime;
                regDoctorObj.EndTime = endTime;
                regDoctorObj.State = state;

                response.RegDoctorList.Add(regDoctorObj);
            }

            return response;
        }

        #endregion

        #region 获取当天医生可用的时间段信息
        /// <summary>
        /// 获取当天医生可用的时间段信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetsplitList")]
        public Response4GetsplitList GetsplitList(Request4GetsplitList request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);
            xmlDoc.AppendChild(root);

            XmlNode SCHEDULEIDNode = xmlDoc.CreateElement("SCHEDULEID");
            SCHEDULEIDNode.InnerText = request.SCHEDULEID;
            root.AppendChild(SCHEDULEIDNode);
            xmlDoc.AppendChild(root);

            XmlNode doctIDNode = xmlDoc.CreateElement("doctID");
            doctIDNode.InnerText = request.doctID;
            root.AppendChild(doctIDNode);
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetsplitList(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetsplitList 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetsplitList", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetsplitList();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.splitList = new List<Response4GetsplitList.Response4SplitList>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");

            foreach (XmlNode xNode in nodes)
            {
                var regDoctorObj = new Response4GetsplitList.Response4SplitList();

                var SCHEMA_NO = xNode.SelectSingleNode("SCHEMA_NO".ToUpper()) == null ? "" : xNode.SelectSingleNode("SCHEMA_NO".ToUpper()).InnerText;
                var DEPT_CODE = xNode.SelectSingleNode("DEPT_CODE".ToUpper()) == null ? "" : xNode.SelectSingleNode("DEPT_CODE".ToUpper()).InnerText;
                var DEPT_NAME = xNode.SelectSingleNode("DEPT_NAME".ToUpper()) == null ? "" : xNode.SelectSingleNode("DEPT_NAME".ToUpper()).InnerText;
                var DOCT_CODE = xNode.SelectSingleNode("DOCT_CODE".ToUpper()) == null ? "" : xNode.SelectSingleNode("DOCT_CODE".ToUpper()).InnerText;
                var DOCT_NAME = xNode.SelectSingleNode("DOCT_NAME".ToUpper()) == null ? "" : xNode.SelectSingleNode("DOCT_NAME".ToUpper()).InnerText;
                var SEE_DATE = xNode.SelectSingleNode("SEE_DATE".ToUpper()) == null ? "" : xNode.SelectSingleNode("SEE_DATE".ToUpper()).InnerText;
                var BEGIN_TIME = xNode.SelectSingleNode("BEGIN_TIME".ToUpper()) == null ? "" : xNode.SelectSingleNode("BEGIN_TIME".ToUpper()).InnerText;
                var END_TIME = xNode.SelectSingleNode("END_TIME".ToUpper()) == null ? "" : xNode.SelectSingleNode("END_TIME".ToUpper()).InnerText;
                var NUM = xNode.SelectSingleNode("NUM".ToUpper()) == null ? "" : xNode.SelectSingleNode("NUM".ToUpper()).InnerText;

                regDoctorObj.SCHEMA_NO = SCHEMA_NO;
                regDoctorObj.DEPT_CODE = DEPT_CODE;
                regDoctorObj.DEPT_NAME = DEPT_NAME;
                regDoctorObj.DOCT_CODE = DOCT_CODE;
                regDoctorObj.DOCT_NAME = DOCT_NAME;
                regDoctorObj.SEE_DATE = SEE_DATE;
                regDoctorObj.BEGIN_TIME = BEGIN_TIME;
                regDoctorObj.END_TIME = END_TIME;
                regDoctorObj.NUM = NUM;

                response.splitList.Add(regDoctorObj);
            }

            return response;
        }

        #endregion

        #region 获取医生最新挂号状态
        /// <summary>
        /// 在确认挂号前获取医生最新的挂号状态
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetRegDoctorState")]
        public Response4GetRegDoctorState GetRegDoctorState(Request4GetRegDoctorState request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode scheduleIdNode = xmlDoc.CreateElement("ScheduleId");
            scheduleIdNode.InnerText = request.ScheduleId;
            root.AppendChild(scheduleIdNode);

            XmlNode docIdNode = xmlDoc.CreateElement("DocId");
            docIdNode.InnerText = request.DoctorId;
            root.AppendChild(docIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetRegDocState(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetRegDocState 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetRegDocState", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetRegDoctorState();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.RegDoctorStateInfo = new Response4GetRegDoctorStateSubRegDoctorStateInfo();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var regDoctorStateObj = new Response4GetRegDoctorStateSubRegDoctorStateInfo();

                var scheduleId = xNode.SelectSingleNode("ScheduleId".ToUpper()) == null ? "" : xNode.SelectSingleNode("ScheduleId".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var subjectId = xNode.SelectSingleNode("SubjectId".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectId".ToUpper()).InnerText;
                var subjectName = xNode.SelectSingleNode("SubjectName".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectName".ToUpper()).InnerText;
                var waitCount = xNode.SelectSingleNode("WaitCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitCount".ToUpper()).InnerText;
                var regCount = xNode.SelectSingleNode("RegCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegCount".ToUpper()).InnerText;
                var regLimit = xNode.SelectSingleNode("RegLimit".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegLimit".ToUpper()).InnerText;
                var regType = xNode.SelectSingleNode("RegType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegType".ToUpper()).InnerText;
                var regAmt = xNode.SelectSingleNode("RegAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegAmt".ToUpper()).InnerText;
                var startTime = xNode.SelectSingleNode("StartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("StartTime".ToUpper()).InnerText;
                var endTime = xNode.SelectSingleNode("EndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("EndTime".ToUpper()).InnerText;
                var state = xNode.SelectSingleNode("State".ToUpper()) == null ? "" : xNode.SelectSingleNode("State".ToUpper()).InnerText;

                regDoctorStateObj.ScheduleId = scheduleId;
                regDoctorStateObj.DoctorId = docId;
                regDoctorStateObj.DoctorName = docName;
                regDoctorStateObj.SubjectId = subjectId;
                regDoctorStateObj.SubjectName = subjectName;
                regDoctorStateObj.WaitCount = waitCount;
                regDoctorStateObj.RegCount = regCount;
                regDoctorStateObj.RegLimit = regLimit;
                regDoctorStateObj.RegType = regType;
                regDoctorStateObj.RegAmt = regAmt;
                regDoctorStateObj.StartTime = startTime;
                regDoctorStateObj.EndTime = endTime;
                regDoctorStateObj.State = state;

                response.RegDoctorStateInfo = regDoctorStateObj;
            }
            return response;
        }
        #endregion

        #region 获取挂号费金额
        /// <summary>
        /// 获取挂号费金额
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetRegAmt")]
        public Response4GetRegAmt GetRegAmt(Request4GetRegAmt request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode iDCardNode = xmlDoc.CreateElement("IDCard");
            iDCardNode.InnerText = request.IdCard;
            root.AppendChild(iDCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode scheduleIdNode = xmlDoc.CreateElement("ScheduleId");
            scheduleIdNode.InnerText = request.ScheduleId;
            root.AppendChild(scheduleIdNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("DocId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            XmlNode subjectIdNode = xmlDoc.CreateElement("SubjectId");
            subjectIdNode.InnerText = request.SubjectId;
            root.AppendChild(subjectIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetRegAmt(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetRegAmt 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetRegAmt", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetRegAmt();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var regAmt = xNode.SelectSingleNode("RegAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegAmt".ToUpper()).InnerText;
                response.RegAmt = regAmt;
            }

            return response;
        }
        #endregion

        #region 挂号处理
        /// <summary>
        /// 提交挂号信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("SaveRegInfo")]
        public Response4SaveRegInfo SaveRegInfo(Request4SaveRegInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode iDCardNode = xmlDoc.CreateElement("IDCard");
            iDCardNode.InnerText = request.IdCard;
            root.AppendChild(iDCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode scheduleIdNode = xmlDoc.CreateElement("ScheduleId");
            scheduleIdNode.InnerText = request.ScheduleId;
            root.AppendChild(scheduleIdNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("DocId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            XmlNode subjectIdNode = xmlDoc.CreateElement("SubjectId");
            subjectIdNode.InnerText = request.SubjectId;
            root.AppendChild(subjectIdNode);

            XmlNode regAmtNode = xmlDoc.CreateElement("RegAmt");
            regAmtNode.InnerText = request.RegAmt;
            root.AppendChild(regAmtNode);

            XmlNode sbConfirmedNode = xmlDoc.CreateElement("SbConfirmed");
            sbConfirmedNode.InnerText = request.SbConfirmed;
            root.AppendChild(sbConfirmedNode);

            XmlNode registrarIdNode = xmlDoc.CreateElement("RegistrarId");
            registrarIdNode.InnerText = request.RegistrarId;
            root.AppendChild(registrarIdNode);

            XmlNode machineIdNode = xmlDoc.CreateElement("MachineId");
            machineIdNode.InnerText = request.MachineId;
            root.AppendChild(machineIdNode);

            XmlNode startTimeNode = xmlDoc.CreateElement("BEGIN_TIME");
            startTimeNode.InnerText = request.StartTime;
            root.AppendChild(startTimeNode);

            XmlNode endTimeNode = xmlDoc.CreateElement("END_TIME");
            endTimeNode.InnerText = request.EndTime;
            root.AppendChild(endTimeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXSaveRegInfo18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXSaveRegInfo18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXSaveRegInfo18", requestXml, responseXml);


            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4SaveRegInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var waitNo = xNode.SelectSingleNode("WaitNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitNo".ToUpper()).InnerText;
                var waitCount = xNode.SelectSingleNode("WaitCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitCount".ToUpper()).InnerText;
                var patType = xNode.SelectSingleNode("PatType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PatType".ToUpper()).InnerText;
                var address = xNode.SelectSingleNode("Address".ToUpper()) == null ? "" : xNode.SelectSingleNode("Address".ToUpper()).InnerText;
                var regTime = xNode.SelectSingleNode("RegTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegTime".ToUpper()).InnerText;
                var predictTime = xNode.SelectSingleNode("PredictTime") == null ? "" : xNode.SelectSingleNode("PredictTime").InnerText;

                response.FlowNo = flowNo;
                response.WaitNo = waitNo;
                response.WaitCount = waitCount;
                response.PatType = patType;
                response.Address = address;
                response.RegTime = regTime;
                response.PredictTime = predictTime;
            }

            return response;
        }

        #endregion

        #region  报到处理
        [HttpPost]
        [ActionName("CheckInBookInfo")]
        public Response4CheckInBookInfo CheckInBookInfo(Request4CheckInBookInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            XmlNode registrarIdNode = xmlDoc.CreateElement("RegistrarId");
            registrarIdNode.InnerText = request.RegistrarId;
            root.AppendChild(registrarIdNode);

            XmlNode machineIdNode = xmlDoc.CreateElement("MachineId");
            machineIdNode.InnerText = request.MachineId;
            root.AppendChild(machineIdNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXCheckInBookInfo18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXCheckInBookInfo18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXCheckInBookInfo18", requestXml, responseXml);

            responseXml = responseXml.ToLower();

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4CheckInBookInfo();
            var node = xmlDoc.SelectSingleNode("/response/resultcode");
            var resultCode = node == null ? "" : node.InnerText;
            node = xmlDoc.SelectSingleNode("/response/errormsg");
            var resultDesc = node == null ? "" : node.InnerText;

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var regInfo = new Response4CheckInBookInfoSubRegInfo();

            var regInfoNode = xmlDoc.SelectSingleNode("/response/resultdata");

            var regFlowNo = regInfoNode.SelectSingleNode("regflowno") == null ? "" : regInfoNode.SelectSingleNode("regflowno").InnerText;
            var waitNo = regInfoNode.SelectSingleNode("waitno") == null ? "" : regInfoNode.SelectSingleNode("waitno").InnerText;
            var waitCount = regInfoNode.SelectSingleNode("waitcount") == null ? "" : regInfoNode.SelectSingleNode("waitcount").InnerText;
            var patType = regInfoNode.SelectSingleNode("pattype") == null ? "" : regInfoNode.SelectSingleNode("pattype").InnerText;
            var regAmt = regInfoNode.SelectSingleNode("regamt") == null ? "" : regInfoNode.SelectSingleNode("regamt").InnerText;
            var address = regInfoNode.SelectSingleNode("address") == null ? "" : regInfoNode.SelectSingleNode("address").InnerText;
            var regTime = regInfoNode.SelectSingleNode("regtime") == null ? "" : regInfoNode.SelectSingleNode("regtime").InnerText;
            var resultMark = regInfoNode.SelectSingleNode("resultmark") == null ? "" : regInfoNode.SelectSingleNode("resultmark").InnerText;

            regInfo.RegFlowNo = regFlowNo;
            regInfo.WaitNo = waitNo;
            regInfo.WaitCount = waitCount;
            regInfo.PatType = patType;
            regInfo.RegAmt = regAmt;
            regInfo.Address = address;
            regInfo.RegTime = regTime;
            regInfo.ResultMark = resultMark;

            response.RegInfo = regInfo;

            return response;
        }

        #endregion 

        /// <summary>
        /// 查询订单是否有效
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPillValid")]
        public Response4GetPillValid GetPillValid(Request4GetPillValid request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode cardNoNode = xmlDoc.CreateElement("card_no");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode pillNoNode = xmlDoc.CreateElement("pill_no");
            pillNoNode.InnerText = request.PillNo;
            root.AppendChild(pillNoNode);

            XmlNode pillTypeNode = xmlDoc.CreateElement("pill_type");
            pillTypeNode.InnerText = request.PillType;
            root.AppendChild(pillTypeNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetPillValid(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetPillValid 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetPillValid", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetPillValid();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            return response;
        }

        #region 查询订单是否有效



        #endregion

        #region 查询已挂号信息
        /// <summary>
        /// 查询已挂号信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetRegInfo")]
        public Response4GetRegInfo GetRegInfo(Request4GetRegInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            XmlNode startDateNode = xmlDoc.CreateElement("StartDate");
            startDateNode.InnerText = request.StartDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("EndDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetRegInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetRegInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetRegInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetRegInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.RegInfoList = new List<Response4GetRegInfoSubRegInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var regInfoObj = new Response4GetRegInfoSubRegInfo();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var clinNo = xNode.SelectSingleNode("ClinNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("ClinNo".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;
                var cardNo = xNode.SelectSingleNode("CardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("CardNo".ToUpper()).InnerText;
                var scheduleId = xNode.SelectSingleNode("ScheduleId".ToUpper()) == null ? "" : xNode.SelectSingleNode("ScheduleId".ToUpper()).InnerText;
                var deptId = xNode.SelectSingleNode("DeptId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptId".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var subjectId = xNode.SelectSingleNode("SubjectId".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectId".ToUpper()).InnerText;
                var subjectName = xNode.SelectSingleNode("SubjectName".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectName".ToUpper()).InnerText;
                var startTime = xNode.SelectSingleNode("StartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("StartTime".ToUpper()).InnerText;
                var endTime = xNode.SelectSingleNode("EndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("EndTime".ToUpper()).InnerText;
                var registrarId = xNode.SelectSingleNode("RegistrarId".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegistrarId".ToUpper()).InnerText;
                var waitNo = xNode.SelectSingleNode("WaitNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitNo".ToUpper()).InnerText;
                var regType = xNode.SelectSingleNode("RegType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegType".ToUpper()).InnerText;
                var regAmt = xNode.SelectSingleNode("RegAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegAmt".ToUpper()).InnerText;
                var regTime = xNode.SelectSingleNode("RegTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegTime".ToUpper()).InnerText;
                var state = xNode.SelectSingleNode("State".ToUpper()) == null ? "" : xNode.SelectSingleNode("State".ToUpper()).InnerText;

                regInfoObj.FlowNo = flowNo;
                regInfoObj.HosPatId = hosPatId;
                regInfoObj.ClinNo = clinNo;
                regInfoObj.IdCard = idCard;
                regInfoObj.CardNo = cardNo;
                regInfoObj.ScheduleId = scheduleId;
                regInfoObj.DeptId = deptId;
                regInfoObj.DeptName = deptName;
                regInfoObj.DoctorId = docId;
                regInfoObj.DoctorName = docName;
                regInfoObj.SubjectId = subjectId;
                regInfoObj.SubjectName = subjectName;
                regInfoObj.RegistrarId = registrarId;
                regInfoObj.WaitNo = waitNo;
                regInfoObj.RegTime = regTime;
                regInfoObj.RegType = regType;
                regInfoObj.RegAmt = regAmt;
                regInfoObj.StartTime = startTime;
                regInfoObj.EndTime = endTime;
                regInfoObj.State = state;

                response.RegInfoList.Add(regInfoObj);
            }

            return response;
        }
        #endregion

        #region 获取患者信息(根据门诊病人信息接口获取)
        /// <summary>
        /// 获取患者信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetPatientInfo")]
        public Response4GetPatientInfo GetPatientInfo(Request4GetPatientInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = "";
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = "";
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = "";
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetClinPatient18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetClinPatient18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetClinPatient18", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetPatientInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.PatientInfo = new Response4GetPatientInfoSubPatientInfo();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var patientInfoObj = new Response4GetPatientInfoSubPatientInfo();
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var name = xNode.SelectSingleNode("Name".ToUpper()) == null ? "" : xNode.SelectSingleNode("Name".ToUpper()).InnerText;
                var sex = xNode.SelectSingleNode("Sex".ToUpper()) == null ? "" : xNode.SelectSingleNode("Sex".ToUpper()).InnerText;
                var birthDay = xNode.SelectSingleNode("BirthDay".ToUpper()) == null ? "" : xNode.SelectSingleNode("BirthDay".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;
                var familyAddress = xNode.SelectSingleNode("FamilyAddress".ToUpper()) == null ? "" : xNode.SelectSingleNode("FamilyAddress".ToUpper()).InnerText;
                var phone = xNode.SelectSingleNode("Phone".ToUpper()) == null ? "" : xNode.SelectSingleNode("Phone".ToUpper()).InnerText;
                var familyPhone = xNode.SelectSingleNode("FamilyPhone".ToUpper()) == null ? "" : xNode.SelectSingleNode("FamilyPhone".ToUpper()).InnerText;
                var clinNo = xNode.SelectSingleNode("ClinNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("ClinNo".ToUpper()).InnerText;
                var cardNo = xNode.SelectSingleNode("CardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("CardNo".ToUpper()).InnerText;
                var payType = xNode.SelectSingleNode("PayType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayType".ToUpper()).InnerText;

                patientInfoObj.PatientId = hosPatId;
                patientInfoObj.InDeptNo = "";
                patientInfoObj.Name = name;
                patientInfoObj.Gender = sex;
                patientInfoObj.Age = "";
                patientInfoObj.Birthdate = birthDay;
                patientInfoObj.IdenNo = idCard;
                patientInfoObj.Phone = phone;
                patientInfoObj.FeeType = payType;
                patientInfoObj.ClinNo = clinNo;

                response.PatientInfo = patientInfoObj;


                //在前置机HospDatabase数据库HospCard加入患者诊疗号，用于在通知功能筛选患者
                try
                {
                    using (var ctx = new HospDatabaseEntity())
                    {
                        var patient = ctx.HospCards.FirstOrDefault(card => card.CardNo == request.CardNo);
                        if (patient == null)
                        {
                            var card = new HospCard();
                            card.PatientId = hosPatId;
                            card.Name = name;
                            card.CardNo = request.CardNo;
                            card.CardType = "0";
                            ctx.HospCards.Add(card);
                            ctx.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.ErrorFormat("新增 HospCard 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                }
            }

            return response;
        }
        #endregion

        #region 获得门诊病人信息
        /// <summary>
        /// 获取患者信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetClinPatient")]
        public Response4GetClinPatient GetClinPatient(Request4GetClinPatient request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = request.HospitalId;
            //root.AppendChild(hospitalIdNode);

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetClinPatient18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetClinPatient18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetClinPatient18", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetClinPatient();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ClinPatientInfo = new Response4GetClinPatientInfoSubClinPatientInfo();

            var nodes = xmlDoc.SelectNodes("/Response/ResultData");

            foreach (XmlNode xNode in nodes)
            {
                var patientInfoObj = new Response4GetClinPatientInfoSubClinPatientInfo();
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var name = xNode.SelectSingleNode("Name".ToUpper()) == null ? "" : xNode.SelectSingleNode("Name".ToUpper()).InnerText;
                var sex = xNode.SelectSingleNode("Sex".ToUpper()) == null ? "" : xNode.SelectSingleNode("Sex".ToUpper()).InnerText;
                var birthDay = xNode.SelectSingleNode("BirthDay".ToUpper()) == null ? "" : xNode.SelectSingleNode("BirthDay".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;
                var familyAddress = xNode.SelectSingleNode("FamilyAddress".ToUpper()) == null ? "" : xNode.SelectSingleNode("FamilyAddress".ToUpper()).InnerText;
                var phone = xNode.SelectSingleNode("Phone".ToUpper()) == null ? "" : xNode.SelectSingleNode("Phone".ToUpper()).InnerText;
                var familyPhone = xNode.SelectSingleNode("FamilyPhone".ToUpper()) == null ? "" : xNode.SelectSingleNode("FamilyPhone".ToUpper()).InnerText;
                var clinNo = xNode.SelectSingleNode("ClinNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("ClinNo".ToUpper()).InnerText;
                var cardNo = xNode.SelectSingleNode("CardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("CardNo".ToUpper()).InnerText;
                var payType = xNode.SelectSingleNode("PayType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayType".ToUpper()).InnerText;
                var pactCode = xNode.SelectSingleNode("PactCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("PactCode".ToUpper()).InnerText;

                patientInfoObj.HosPatId = hosPatId;
                patientInfoObj.Name = name;
                patientInfoObj.Sex = sex;
                patientInfoObj.BirthDay = birthDay;
                patientInfoObj.IdCard = idCard;
                patientInfoObj.FamilyAddress = familyAddress;
                patientInfoObj.Phone = phone;
                patientInfoObj.FamilyPhone = familyPhone;
                patientInfoObj.ClinNo = clinNo;
                patientInfoObj.CardNo = cardNo;
                patientInfoObj.PayType = payType;
                patientInfoObj.PactCode = pactCode;

                response.ClinPatientInfo = patientInfoObj;

                //在前置机HospDatabase数据库HospCard加入患者诊疗号，用于在通知功能筛选患者
                try
                {
                    using (var ctx = new HospDatabaseEntity())
                    {
                        var patient = ctx.HospCards.FirstOrDefault(card => card.CardNo == request.CardNo);
                        if (patient == null)
                        {
                            var card = new HospCard();
                            card.PatientId = hosPatId;
                            card.Name = name;
                            card.CardNo = request.CardNo;
                            card.CardType = "0";
                            ctx.HospCards.Add(card);
                            ctx.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.ErrorFormat("新增 HospCard 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                }
            }

            return response;
        }

        #endregion

        #region 编辑门诊病人信息
        /// <summary>
        /// 编辑门诊病人信息（现只用于修改门诊病人的手机号）
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("EditClinPatient")]
        public Response4EditClinPatient EditClinPatient(Request4EditClinPatient request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode nameNode = xmlDoc.CreateElement("Name");
            nameNode.InnerText = request.Name;
            root.AppendChild(nameNode);

            XmlNode sexNode = xmlDoc.CreateElement("Sex");
            sexNode.InnerText = request.Sex;
            root.AppendChild(sexNode);

            XmlNode birthDayNode = xmlDoc.CreateElement("BirthDay");
            birthDayNode.InnerText = request.BirthDay;
            root.AppendChild(birthDayNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode familyAddressNode = xmlDoc.CreateElement("FamilyAddress");
            familyAddressNode.InnerText = request.FamilyAddress;
            root.AppendChild(familyAddressNode);

            XmlNode phoneNode = xmlDoc.CreateElement("Phone");
            phoneNode.InnerText = request.Phone;
            root.AppendChild(phoneNode);

            XmlNode familyPhoneNode = xmlDoc.CreateElement("FamilyPhone");
            familyPhoneNode.InnerText = request.FamilyPhone;
            root.AppendChild(familyPhoneNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode payTypeNode = xmlDoc.CreateElement("PayType");
            payTypeNode.InnerText = request.PayType;
            root.AppendChild(payTypeNode);

            XmlNode keyFieldNode = xmlDoc.CreateElement("KeyField");
            keyFieldNode.InnerText = request.KeyField;
            root.AppendChild(keyFieldNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXEditPatient18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXEditPatient18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXEditPatient18", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4EditClinPatient();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            return response;
        }
        #endregion

        #region 新增门诊病人信息

        [HttpPost]
        [ActionName("NewClinPatient")]
        public Response4NewClinPatient NewClinPatient(Request4NewClinPatient request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode nameNode = xmlDoc.CreateElement("PatientName");
            nameNode.InnerText = request.PatientName;
            root.AppendChild(nameNode);

            XmlNode sexNode = xmlDoc.CreateElement("Sex");
            sexNode.InnerText = request.Sex;
            root.AppendChild(sexNode);

            XmlNode birthDayNode = xmlDoc.CreateElement("BirthDay");
            birthDayNode.InnerText = request.BirthDay;
            root.AppendChild(birthDayNode);

            XmlNode familyAddressNode = xmlDoc.CreateElement("Address");
            familyAddressNode.InnerText = request.Address;
            root.AppendChild(familyAddressNode);

            XmlNode nationNode = xmlDoc.CreateElement("Nation");
            nationNode.InnerText = request.Nation;
            root.AppendChild(nationNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode phoneNode = xmlDoc.CreateElement("Phone");
            phoneNode.InnerText = request.Phone;
            root.AppendChild(phoneNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = ""; //为空
            root.AppendChild(cardNoNode);

            XmlNode machineIdNode = xmlDoc.CreateElement("MachineId");
            machineIdNode.InnerText = "008881";  //微信建卡
            root.AppendChild(machineIdNode);


            XmlNode PROVINCE_CODENode = xmlDoc.CreateElement("PROVINCE_CODE");
            PROVINCE_CODENode.InnerText = request.PROVINCE_CODE;
            root.AppendChild(PROVINCE_CODENode);

            XmlNode PROVINCE_NAMENode = xmlDoc.CreateElement("PROVINCE_NAME");
            PROVINCE_NAMENode.InnerText = request.PROVINCE_NAME;
            root.AppendChild(PROVINCE_NAMENode);

            XmlNode CITY_CODENode = xmlDoc.CreateElement("CITY_CODE");
            CITY_CODENode.InnerText = request.CITY_CODE;
            root.AppendChild(CITY_CODENode);

            XmlNode CITY_NAMENode = xmlDoc.CreateElement("CITY_NAME");
            CITY_NAMENode.InnerText = request.CITY_NAME;
            root.AppendChild(CITY_NAMENode);

            XmlNode RIGION_CODENode = xmlDoc.CreateElement("RIGION_CODE");
            RIGION_CODENode.InnerText = request.RIGION_CODE;
            root.AppendChild(RIGION_CODENode);

            XmlNode REGION_NAMENode = xmlDoc.CreateElement("REGION_NAME");
            REGION_NAMENode.InnerText = request.REGION_NAME;
            root.AppendChild(REGION_NAMENode);


            XmlNode TOWN_CODENode = xmlDoc.CreateElement("TOWN_CODE");
            TOWN_CODENode.InnerText = request.TOWN_CODE;
            root.AppendChild(TOWN_CODENode);

            XmlNode TOWN_NAMENode = xmlDoc.CreateElement("TOWN_NAME");
            TOWN_NAMENode.InnerText = request.TOWN_NAME;
            root.AppendChild(TOWN_NAMENode);

            XmlNode DETAIL_ADDRESSNode = xmlDoc.CreateElement("DETAIL_ADDRESS");
            DETAIL_ADDRESSNode.InnerText = request.DETAIL_ADDRESS;
            root.AppendChild(DETAIL_ADDRESSNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXNewPatient18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXNewPatient18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXNewPatient18", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4NewClinPatient();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            var resultNode = xmlDoc.SelectSingleNode("/Response/ResultData");

            if (resultNode != null)
            {
                var clinNo = resultNode.SelectSingleNode("CLINNO").InnerText ?? "";
                var cardNo = resultNode.SelectSingleNode("CARDNO").InnerText ?? "";
                var patId = resultNode.SelectSingleNode("HOSPATID").InnerText ?? "";

                response.HospPatId = patId;
                response.CardNo = cardNo;
                response.ClinNo = clinNo;
            }

            return response;
        }

        #endregion


        #region 获取省份信息

        [HttpPost]
        [ActionName("GetPROVINCE")]
        public Response4GetPROVINCE GetPROVINCE(Request4GetPROVINCE request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetPROVINCE();
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetPROVINCE 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetPROVINCE", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetPROVINCE();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ResultList = new List<Response4Result>();
            var nodes = xmlDoc.SelectNodes("/Response/Result");
            foreach (XmlNode xNode in nodes)
            {
                var hospInfoObj = new Response4Result();
                var code = xNode.SelectSingleNode("PROVINCE_CODE").InnerText;
                var name = xNode.SelectSingleNode("PROVINCE_NAME").InnerText;

                hospInfoObj.PROVINCE_CODE = code;
                hospInfoObj.PROVINCE_NAME = name;

                response.ResultList.Add(hospInfoObj);
            }

            return response;
        }

        #endregion

        #region 获取市信息

        [HttpPost]
        [ActionName("GetCity")]
        public Response4GetCity GetCity(Request4GetCity request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode PROVINCE_CODENode = xmlDoc.CreateElement("PROVINCE_CODE");
            PROVINCE_CODENode.InnerText = request.PROVINCE_CODE;
            root.AppendChild(PROVINCE_CODENode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetCity(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetCity 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetCity", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetCity();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.CITYList = new List<Response4CITY>();
            var nodes = xmlDoc.SelectNodes("/Response/Result");
            foreach (XmlNode xNode in nodes)
            {
                var hospInfoObj = new Response4CITY();
                var code = xNode.SelectSingleNode("CITY_CODE").InnerText;
                var name = xNode.SelectSingleNode("CITY_NAME").InnerText;

                hospInfoObj.CITY_CODE = code;
                hospInfoObj.CITY_NAME = name;

                response.CITYList.Add(hospInfoObj);
            }

            return response;
        }

        #endregion

        #region 获取区县信息

        [HttpPost]
        [ActionName("GetDistrict")]
        public Response4GetDistrict GetDistrict(Request4GetDistrict request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode CITY_CODENode = xmlDoc.CreateElement("CITY_CODE");
            CITY_CODENode.InnerText = request.CITY_CODE;
            root.AppendChild(CITY_CODENode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetDistrict(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetCity 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetCity", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetDistrict();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.DISTRICTList = new List<Response4DISTRICT>();
            var nodes = xmlDoc.SelectNodes("/Response/Result");
            foreach (XmlNode xNode in nodes)
            {
                var hospInfoObj = new Response4DISTRICT();
                var code = xNode.SelectSingleNode("DISTRICT_CODE").InnerText;
                var name = xNode.SelectSingleNode("DISTRICT_NAME").InnerText;

                hospInfoObj.DISTRICT_CODE = code;
                hospInfoObj.DISTRICT_NAME = name;

                response.DISTRICTList.Add(hospInfoObj);
            }

            return response;
        }

        #endregion

        #region 获取街道信息

        [HttpPost]
        [ActionName("GetTOWN")]
        public Response4GetDistrict GetTOWN(Request4GetDistrict request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode CITY_CODENode = xmlDoc.CreateElement("DISTRICT_CODE");
            CITY_CODENode.InnerText = request.CITY_CODE;
            root.AppendChild(CITY_CODENode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetTOWN(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetTOWN  失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetTOWN ", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetDistrict();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.DISTRICTList = new List<Response4DISTRICT>();
            var nodes = xmlDoc.SelectNodes("/Response/Result");
            foreach (XmlNode xNode in nodes)
            {
                var hospInfoObj = new Response4DISTRICT();
                var code = xNode.SelectSingleNode("TOWN_CODE").InnerText;
                var name = xNode.SelectSingleNode("TOWN_NAME").InnerText;

                hospInfoObj.DISTRICT_CODE = code;
                hospInfoObj.DISTRICT_NAME = name;

                response.DISTRICTList.Add(hospInfoObj);
            }

            return response;
        }

        #endregion 

        #region 获得住院病人信息
        /// <summary>
        /// 获得住院病人信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetWardPatient")]
        public Response4GetWardPatient GetWardPatient(Request4GetWardPatient request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            //XmlNode hospitalIdNode = xmlDoc.CreateElement("hospitalId");
            //hospitalIdNode.InnerText = request.HospitalId;
            //root.AppendChild(hospitalIdNode);

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("WardNo");
            cardNoNode.InnerText = request.WardNo;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetWardPatient(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetWardPatient 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetWardPatient", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetWardPatient();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.WardPatientInfo = new Response4GetWardPatientInfoSubWardPatientInfo();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var patientInfoObj = new Response4GetWardPatientInfoSubWardPatientInfo();
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var name = xNode.SelectSingleNode("Name".ToUpper()) == null ? "" : xNode.SelectSingleNode("Name".ToUpper()).InnerText;
                var sex = xNode.SelectSingleNode("Sex".ToUpper()) == null ? "" : xNode.SelectSingleNode("Sex".ToUpper()).InnerText;
                var birthDay = xNode.SelectSingleNode("BirthDay".ToUpper()) == null ? "" : xNode.SelectSingleNode("BirthDay".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;
                var familyAddress = xNode.SelectSingleNode("FamilyAddress".ToUpper()) == null ? "" : xNode.SelectSingleNode("FamilyAddress".ToUpper()).InnerText;
                var phone = xNode.SelectSingleNode("Phone".ToUpper().ToUpper()) == null ? "" : xNode.SelectSingleNode("Phone".ToUpper()).InnerText;
                var familyPhone = xNode.SelectSingleNode("FamilyPhone".ToUpper()) == null ? "" : xNode.SelectSingleNode("FamilyPhone".ToUpper()).InnerText;
                var wardNo = xNode.SelectSingleNode("WardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("WardNo".ToUpper()).InnerText;
                var payType = xNode.SelectSingleNode("PayType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayType".ToUpper()).InnerText;

                patientInfoObj.HosPatId = hosPatId;
                patientInfoObj.Name = name;
                patientInfoObj.Sex = sex;
                patientInfoObj.BirthDay = birthDay;
                patientInfoObj.IdCard = idCard;
                patientInfoObj.FamilyAddress = familyAddress;
                patientInfoObj.Phone = phone;
                patientInfoObj.FamilyPhone = familyPhone;
                patientInfoObj.WardNo = wardNo;
                patientInfoObj.PayType = payType;

                response.WardPatientInfo = patientInfoObj;
            }

            return response;
        }
        #endregion

        #region 获取可预约科室列表
        /// <summary>
        /// 获取允许预约的科室列表，不提供预约科室的功能
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetBookDeptList")]
        public Response4GetBookDeptList GetBookDeptList(Request4GetBookDeptList request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetBookDeptList();
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetBookDeptList 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetBookDeptList", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetBookDeptList();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;


            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.BookDeptList = new List<Response4GetBookDeptListSubBookDeptInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var regDeptObj = new Response4GetBookDeptListSubBookDeptInfo();

                var deptId = xNode.SelectSingleNode("DeptId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptId".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;

                regDeptObj.DeptId = deptId;
                regDeptObj.DeptName = deptName;

                response.BookDeptList.Add(regDeptObj);
            }

            return response;
        }
        #endregion

        #region 获取可预约医生列表
        /// <summary>
        /// 获取允许预约科室中的开诊的医生列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetBookDoctorList")]
        public Response4GetBookDoctorList GetBookDoctorList(Request4GetBookDoctorList request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetBookDocList(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetBookDocList 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetBookDocList", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetBookDoctorList();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.BookDoctorList = new List<Response4GetBookDoctorListSubBookDoctorInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var bookDoctorObj = new Response4GetBookDoctorListSubBookDoctorInfo();

                var scheduleId = xNode.SelectSingleNode("ScheduleId".ToUpper()) == null ? "" : xNode.SelectSingleNode("ScheduleId".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var subjectId = xNode.SelectSingleNode("SubjectId".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectId".ToUpper()).InnerText;
                var subjectName = xNode.SelectSingleNode("SubjectName".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectName".ToUpper()).InnerText;
                var bookCount = xNode.SelectSingleNode("BookCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookCount".ToUpper()).InnerText;
                var bookLimit = xNode.SelectSingleNode("BookLimit".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookLimit".ToUpper()).InnerText;
                var regType = xNode.SelectSingleNode("RegType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegType".ToUpper()).InnerText;
                var regAmt = xNode.SelectSingleNode("RegAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegAmt".ToUpper()).InnerText;
                var startTime = xNode.SelectSingleNode("StartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("StartTime".ToUpper()).InnerText;
                var endTime = xNode.SelectSingleNode("EndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("EndTime".ToUpper()).InnerText;
                var bookStartTime = xNode.SelectSingleNode("BookStartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookStartTime".ToUpper()).InnerText;
                var bookEndTime = xNode.SelectSingleNode("BookEndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookEndTime".ToUpper()).InnerText;

                bookDoctorObj.ScheduleId = scheduleId;
                bookDoctorObj.DoctorId = docId;
                bookDoctorObj.DoctorName = docName;
                bookDoctorObj.SubjectId = subjectId;
                bookDoctorObj.SubjectName = subjectName;
                bookDoctorObj.BookCount = bookCount;
                bookDoctorObj.BookLimit = bookLimit;
                bookDoctorObj.RegType = regType;
                bookDoctorObj.RegAmt = regAmt;
                bookDoctorObj.StartTime = startTime;
                bookDoctorObj.EndTime = endTime;
                bookDoctorObj.BookStartTime = bookStartTime;
                bookDoctorObj.BookEndTime = bookEndTime;

                response.BookDoctorList.Add(bookDoctorObj);
            }

            return response;
        }

        #endregion

        #region 获取医生当班次可预约时段列表
        /// <summary>
        /// 获取允许预约的医生的可预约时间段列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetBookDoctorTimeTable")]
        public Response4GetBookDoctorTimeTable GetBookDoctorTimeTable(Request4GetBookDoctorTimeTable request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode scheduleIdNode = xmlDoc.CreateElement("ScheduleId");
            scheduleIdNode.InnerText = request.ScheduleId;
            root.AppendChild(scheduleIdNode);

            XmlNode docIdNode = xmlDoc.CreateElement("DocId");
            docIdNode.InnerText = request.DoctorId;
            root.AppendChild(docIdNode);

            XmlNode startDateNode = xmlDoc.CreateElement("StartDate");
            startDateNode.InnerText = request.StartDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("EndDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetBookDocTimeTable(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetBookDocTimeTable 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetBookDocTimeTable", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetBookDoctorTimeTable();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.BookDoctorTimeList = new List<Response4GetBookDoctorTimeSubBookDoctorTime>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var bookDoctorTimeObj = new Response4GetBookDoctorTimeSubBookDoctorTime();

                var scheduleId = xNode.SelectSingleNode("ScheduleId".ToUpper()) == null ? "" : xNode.SelectSingleNode("ScheduleId".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var subjectId = xNode.SelectSingleNode("SubjectId".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectId".ToUpper()).InnerText;
                var subjectName = xNode.SelectSingleNode("SubjectName".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectName".ToUpper()).InnerText;
                var bookCount = xNode.SelectSingleNode("BookCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookCount".ToUpper()).InnerText;
                var bookLimit = xNode.SelectSingleNode("BookLimit".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookLimit".ToUpper()).InnerText;
                var spanStartTime = xNode.SelectSingleNode("SpanStartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("SpanStartTime".ToUpper()).InnerText;
                var spanEndTime = xNode.SelectSingleNode("SpanEndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("SpanEndTime".ToUpper()).InnerText;

                bookDoctorTimeObj.ScheduleId = scheduleId;
                bookDoctorTimeObj.DoctorId = docId;
                bookDoctorTimeObj.DoctorName = docName;
                bookDoctorTimeObj.SubjectId = subjectId;
                bookDoctorTimeObj.SubjectName = subjectName;
                bookDoctorTimeObj.BookCount = bookCount;
                bookDoctorTimeObj.BookLimit = bookLimit;
                bookDoctorTimeObj.SpanStartTime = spanStartTime;
                bookDoctorTimeObj.SpanEndTime = spanEndTime;

                response.BookDoctorTimeList.Add(bookDoctorTimeObj);
            }
            return response;
        }
        #endregion

        #region 获取医生7天排班信息
        /// <summary>
        /// 获取允许预约的医生的可预约时间段列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetDocOpenTimeTable")]
        public Response4GetDocOpenTimeTable GetDocOpenTimeTable(Request4GetDocOpenTimeTable request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode docIdNode = xmlDoc.CreateElement("DocId");
            docIdNode.InnerText = request.DocId;
            root.AppendChild(docIdNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                //responseXml = wsClient.DXGetDocOpenTimeTable(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetDocOpenTimeTable 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetDocOpenTimeTable", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetDocOpenTimeTable();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.OpenTimeList = new List<Response4GetDocOpenTimeTableSubOpenTimeInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");

            foreach (XmlNode xNode in nodes)
            {
                var openTimeObj = new Response4GetDocOpenTimeTableSubOpenTimeInfo();

                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var seeDate = xNode.SelectSingleNode("SeeDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("SeeDate".ToUpper()).InnerText;
                var mTime = xNode.SelectSingleNode("MTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("MTime".ToUpper()).InnerText;
                var fmTime = xNode.SelectSingleNode("FMTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("FMTime".ToUpper()).InnerText;


                openTimeObj.DocId = docId;
                openTimeObj.DocName = docName;
                openTimeObj.SeeDate = seeDate;
                openTimeObj.MTime = mTime;
                openTimeObj.FMTime = fmTime;

                response.OpenTimeList.Add(openTimeObj);
            }
            return response;
        }
        #endregion

        #region 获取医生最新预约状态
        /// <summary>
        /// 用于在确认预约前获取医生最新的预约状态
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetBookDoctorState")]
        public Response4GetBookDoctorState GetBookDoctorState(Request4GetBookDoctorState request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode scheduleIdNode = xmlDoc.CreateElement("ScheduleId");
            scheduleIdNode.InnerText = request.ScheduleId;
            root.AppendChild(scheduleIdNode);

            XmlNode docIdNode = xmlDoc.CreateElement("DocId");
            docIdNode.InnerText = request.DoctorId;
            root.AppendChild(docIdNode);

            XmlNode startDateNode = xmlDoc.CreateElement("StartDate");
            startDateNode.InnerText = request.StartDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("EndDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetBookDocState(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetBookDocState 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetBookDocState", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetBookDoctorState();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.BookDoctorState = new Response4GetBookDoctorStateSubBookDoctorState();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var bookDoctorStateObj = new Response4GetBookDoctorStateSubBookDoctorState();

                var scheduleId = xNode.SelectSingleNode("ScheduleId".ToUpper()) == null ? "" : xNode.SelectSingleNode("ScheduleId".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var subjectId = xNode.SelectSingleNode("SubjectId".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectId".ToUpper()).InnerText;
                var subjectName = xNode.SelectSingleNode("SubjectName".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectName".ToUpper()).InnerText;
                var bookCount = xNode.SelectSingleNode("BookCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookCount".ToUpper()).InnerText;
                var bookLimit = xNode.SelectSingleNode("BookLimit".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookLimit".ToUpper()).InnerText;
                var regType = xNode.SelectSingleNode("RegType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegType".ToUpper()).InnerText;
                var regAmt = xNode.SelectSingleNode("RegAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegAmt".ToUpper()).InnerText;
                var startTime = xNode.SelectSingleNode("StartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("StartTime".ToUpper()).InnerText;
                var endTime = xNode.SelectSingleNode("EndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("EndTime".ToUpper()).InnerText;
                var bookStartTime = xNode.SelectSingleNode("BookStartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookStartTime".ToUpper()).InnerText;
                var bookEndTime = xNode.SelectSingleNode("BookEndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookEndTime".ToUpper()).InnerText;

                bookDoctorStateObj.ScheduleId = scheduleId;
                bookDoctorStateObj.DoctorId = docId;
                bookDoctorStateObj.DoctorName = docName;
                bookDoctorStateObj.SubjectId = subjectId;
                bookDoctorStateObj.SubjectName = subjectName;
                bookDoctorStateObj.BookCount = bookCount;
                bookDoctorStateObj.BookLimit = bookLimit;
                bookDoctorStateObj.RegType = regType;
                bookDoctorStateObj.RegAmt = regAmt;
                bookDoctorStateObj.StartTime = startTime;
                bookDoctorStateObj.EndTime = endTime;
                bookDoctorStateObj.BookStartTime = bookStartTime;
                bookDoctorStateObj.BookEndTime = bookEndTime;

                response.BookDoctorState = bookDoctorStateObj;
            }

            return response;
        }

        #endregion

        #region 查询已预约信息
        /// <summary>
        /// 查询病人的预约信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetBookInfo")]
        public Response4GetBookInfo GetBookInfo(Request4GetBookInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            XmlNode startDateNode = xmlDoc.CreateElement("StartDate");
            startDateNode.InnerText = request.StartDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("EndDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetBookInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetBookInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetBookInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetBookInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.BookInfoList = new List<Response4GetBookInfoSubBookInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var bookInfoObj = new Response4GetBookInfoSubBookInfo();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var clinNo = xNode.SelectSingleNode("ClinNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("ClinNo".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;
                var cardNo = xNode.SelectSingleNode("CardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("CardNo".ToUpper()).InnerText;
                var phone = xNode.SelectSingleNode("Phone".ToUpper()) == null ? "" : xNode.SelectSingleNode("Phone".ToUpper()).InnerText;
                var scheduleId = xNode.SelectSingleNode("ScheduleId".ToUpper()) == null ? "" : xNode.SelectSingleNode("ScheduleId".ToUpper()).InnerText;
                var deptId = xNode.SelectSingleNode("DeptId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptId".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var subjectId = xNode.SelectSingleNode("SubjectId".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectId".ToUpper()).InnerText;
                var subjectName = xNode.SelectSingleNode("SubjectName".ToUpper()) == null ? "" : xNode.SelectSingleNode("SubjectName".ToUpper()).InnerText;
                var startTime = xNode.SelectSingleNode("StartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("StartTime".ToUpper()).InnerText;
                var endTime = xNode.SelectSingleNode("EndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("EndTime".ToUpper()).InnerText;
                var regType = xNode.SelectSingleNode("RegType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegType".ToUpper()).InnerText;
                var bookTime = xNode.SelectSingleNode("BookTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookTime".ToUpper()).InnerText;
                var bookStartTime = xNode.SelectSingleNode("BookStartTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookStartTime".ToUpper()).InnerText;
                var bookEndTime = xNode.SelectSingleNode("BookEndTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookEndTime".ToUpper()).InnerText;
                var bookNo = xNode.SelectSingleNode("BookNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookNo".ToUpper()).InnerText;
                var state = xNode.SelectSingleNode("State".ToUpper()) == null ? "" : xNode.SelectSingleNode("State".ToUpper()).InnerText;
                var regFlowNo = xNode.SelectSingleNode("RegFlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegFlowNo".ToUpper()).InnerText;
                var waitNo = xNode.SelectSingleNode("WaitNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitNo".ToUpper()).InnerText;
                var waitCount = xNode.SelectSingleNode("WaitCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("WaitCount".ToUpper()).InnerText;
                var regTime = xNode.SelectSingleNode("RegTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("RegTime".ToUpper()).InnerText;
                var address = xNode.SelectSingleNode("Address".ToUpper()) == null ? "" : xNode.SelectSingleNode("Address".ToUpper()).InnerText;

                bookInfoObj.FlowNo = flowNo;
                bookInfoObj.HosPatId = hosPatId;
                bookInfoObj.ClinNo = clinNo;
                bookInfoObj.IdCard = idCard;
                bookInfoObj.CardNo = cardNo;
                bookInfoObj.Phone = phone;
                bookInfoObj.ScheduleId = scheduleId;
                bookInfoObj.DeptId = deptId;
                bookInfoObj.DeptName = deptName;
                bookInfoObj.DoctorId = docId;
                bookInfoObj.DoctorName = docName;
                bookInfoObj.SubjectId = subjectId;
                bookInfoObj.SubjectName = subjectName;
                bookInfoObj.StartTime = startTime;
                bookInfoObj.EndTime = endTime;
                bookInfoObj.RegType = regType;
                bookInfoObj.BookTime = bookTime;
                bookInfoObj.BookStartTime = bookStartTime;
                bookInfoObj.BookEndTime = bookEndTime;
                bookInfoObj.BookNo = bookNo;
                bookInfoObj.State = state;
                bookInfoObj.RegFlowNo = regFlowNo;
                bookInfoObj.WaitNo = waitNo;

                response.BookInfoList.Add(bookInfoObj);
            }

            return response;
        }
        #endregion

        #region 预约确认处理
        /// <summary>
        /// 提交预约信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("SaveBookInfo")]
        public Response4SaveBookInfo SaveBookInfo(Request4SaveBookInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode iDCardNode = xmlDoc.CreateElement("IDCard");
            iDCardNode.InnerText = request.IdCard;
            root.AppendChild(iDCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode phoneNode = xmlDoc.CreateElement("Phone");
            phoneNode.InnerText = request.Phone;
            root.AppendChild(phoneNode);

            XmlNode scheduleIdNode = xmlDoc.CreateElement("ScheduleId");
            scheduleIdNode.InnerText = request.ScheduleId;
            root.AppendChild(scheduleIdNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            XmlNode doctorIdNode = xmlDoc.CreateElement("DocId");
            doctorIdNode.InnerText = request.DoctorId;
            root.AppendChild(doctorIdNode);

            XmlNode subjectIdNode = xmlDoc.CreateElement("SubjectId");
            subjectIdNode.InnerText = request.SubjectId;
            root.AppendChild(subjectIdNode);

            XmlNode bookStartTimeNode = xmlDoc.CreateElement("BookStartTime");
            bookStartTimeNode.InnerText = request.BookStartTime;
            root.AppendChild(bookStartTimeNode);

            XmlNode bookEndTimedNode = xmlDoc.CreateElement("BookEndTime");
            bookEndTimedNode.InnerText = request.BookEndTime;
            root.AppendChild(bookEndTimedNode);

            XmlNode registrarIdNode = xmlDoc.CreateElement("RegistrarId");
            registrarIdNode.InnerText = request.RegistrarId;
            root.AppendChild(registrarIdNode);

            XmlNode machineIdNode = xmlDoc.CreateElement("MachineId");
            machineIdNode.InnerText = request.MachineId;
            root.AppendChild(machineIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXSaveBookInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXSaveBookInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXSaveBookInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4SaveBookInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var bookNo = xNode.SelectSingleNode("BookNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookNo".ToUpper()).InnerText;
                var bookTime = xNode.SelectSingleNode("BookTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("BookTime".ToUpper()).InnerText;

                response.FlowNo = flowNo;
                response.BookNo = bookNo;
                response.BookTime = bookTime;
            }

            return response;
        }
        #endregion

        #region 预约取消处理
        /// <summary>
        /// 取消预约处理
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("CancelBookInfo")]
        public Response4CancelBookInfo CancelBookInfo(Request4CancelBookInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            XmlNode registrarIdNode = xmlDoc.CreateElement("RegistrarId");
            registrarIdNode.InnerText = request.RegistrarId;
            root.AppendChild(registrarIdNode);

            XmlNode machineIdNode = xmlDoc.CreateElement("MachineId");
            machineIdNode.InnerText = request.MachineId;
            root.AppendChild(machineIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXCancelBookInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXCancelBookInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXCancelBookInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4CancelBookInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var resultMark = xNode.SelectSingleNode("ResultMark".ToUpper()) == null ? "" : xNode.SelectSingleNode("ResultMark".ToUpper()).InnerText;
                response.ResultMark = resultMark;
            }

            return response;
        }
        #endregion

        #region 获取等待人数
        /// <summary>
        /// 获取等待人数
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetWaitNum")]
        public Response4GetWaitNum GetWaitNum(Request4GetWaitNum request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetWaitNum(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetWaitNum 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetWaitNum", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetWaitNum();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;


            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.WaitNumInfoList = new List<Response4GetWaitNumSubWaitNumInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var waitNumInfoObj = new Response4GetWaitNumSubWaitNumInfo();

                var deptName = xNode.SelectSingleNode("DEPT_NAME") == null ? "" : xNode.SelectSingleNode("DEPT_NAME").InnerText;
                var doctorName = xNode.SelectSingleNode("DOCT_NAME") == null ? "" : xNode.SelectSingleNode("DOCT_NAME").InnerText;
                var waitNo = xNode.SelectSingleNode("WAITNO ") == null ? "" : xNode.SelectSingleNode("WAITNO ").InnerText;

                waitNumInfoObj.DeptName = deptName;
                waitNumInfoObj.DoctorName = doctorName;
                waitNumInfoObj.WaitNo = waitNo;

                response.WaitNumInfoList.Add(waitNumInfoObj);
            }

            return response;
        }
        #endregion

        #region 获取检验、检查单信息
        /// <summary>
        /// 获取检验、检查单信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetExamInfo")]
        public Response4GetExamInfo GetExamInfo(Request4GetExamInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode examTypeNode = xmlDoc.CreateElement("ExamType");
            examTypeNode.InnerText = request.ExamType;
            root.AppendChild(examTypeNode);

            XmlNode startDateNode = xmlDoc.CreateElement("StartDate");
            startDateNode.InnerText = request.StartDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("EndDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetExamInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetExamInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetExamInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetExamInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;


            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ExamInfoList = new List<Response4GetExamInfoSubExamInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var examInfoObj = new Response4GetExamInfoSubExamInfo();

                var examId = xNode.SelectSingleNode("ExamId") == null ? "" : xNode.SelectSingleNode("ExamId").InnerText;
                var examType = xNode.SelectSingleNode("ExamType") == null ? "" : xNode.SelectSingleNode("ExamType").InnerText;
                var operDate = xNode.SelectSingleNode("OperDate") == null ? "" : xNode.SelectSingleNode("OperDate").InnerText;
                var operDocName = xNode.SelectSingleNode("OperDocName") == null ? "" : xNode.SelectSingleNode("OperDocName").InnerText;
                var operDocDept = xNode.SelectSingleNode("OperDocDept") == null ? "" : xNode.SelectSingleNode("OperDocDept").InnerText;
                var eaxmItem = xNode.SelectSingleNode("EaxmItem") == null ? "" : xNode.SelectSingleNode("EaxmItem").InnerText;
                var cardNo = xNode.SelectSingleNode("CardNo") == null ? "" : xNode.SelectSingleNode("CardNo").InnerText;
                var name = xNode.SelectSingleNode("Name") == null ? "" : xNode.SelectSingleNode("Name").InnerText;
                var sex = xNode.SelectSingleNode("Sex") == null ? "" : xNode.SelectSingleNode("Sex").InnerText;
                var reportDate = xNode.SelectSingleNode("ReportDate") == null ? "" : xNode.SelectSingleNode("ReportDate").InnerText;

                examInfoObj.ExamId = examId;
                examInfoObj.ExamType = examType;
                examInfoObj.OperDate = operDate;
                examInfoObj.OperDocName = operDocName;
                examInfoObj.OperDocDept = operDocDept;
                examInfoObj.ExamItem = eaxmItem;
                examInfoObj.CardNo = cardNo;
                examInfoObj.Name = name;
                examInfoObj.Sex = sex;
                examInfoObj.ReportDate = reportDate;

                response.ExamInfoList.Add(examInfoObj);
            }

            return response;
        }
        #endregion

        #region 获取检验、检查单结果信息
        /// <summary>
        /// 获取检验、检查单结果信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetExamDetail")]
        public Response4GetExamDetail GetExamDetail(Request4GetExamDetail request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode examTypeNode = xmlDoc.CreateElement("ExamType");
            examTypeNode.InnerText = request.ExamType;
            root.AppendChild(examTypeNode);

            XmlNode examIdNode = xmlDoc.CreateElement("ExamId");
            examIdNode.InnerText = request.ExamId;
            root.AppendChild(examIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetExamDetail(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 getDeptInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("getDeptInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetExamDetail();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;


            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ExamDetailInfoList = new List<Response4GetExamDetailSubExamDetailInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var examDetailObj = new Response4GetExamDetailSubExamDetailInfo();

                var examId = xNode.SelectSingleNode("ExamId") == null ? "" : xNode.SelectSingleNode("ExamId").InnerText;
                var examType = xNode.SelectSingleNode("ExamType") == null ? "" : xNode.SelectSingleNode("ExamType").InnerText;
                var eaxmItem = xNode.SelectSingleNode("EaxmItem") == null ? "" : xNode.SelectSingleNode("EaxmItem").InnerText;
                var reportDate = xNode.SelectSingleNode("ReportDate") == null ? "" : xNode.SelectSingleNode("ReportDate").InnerText;
                var report = xNode.SelectSingleNode("Report") == null ? "" : xNode.SelectSingleNode("Report").InnerText;
                var conclusion = xNode.SelectSingleNode("Conclusion") == null ? "" : xNode.SelectSingleNode("Conclusion").InnerText;
                var detailItem = xNode.SelectSingleNode("DetailItem") == null ? "" : xNode.SelectSingleNode("DetailItem").InnerText;
                var result = xNode.SelectSingleNode("Result") == null ? "" : xNode.SelectSingleNode("Result").InnerText;
                var unit = xNode.SelectSingleNode("Unit") == null ? "" : xNode.SelectSingleNode("Unit").InnerText;
                var alert = xNode.SelectSingleNode("Alert") == null ? "" : xNode.SelectSingleNode("Alert").InnerText;
                var rang = xNode.SelectSingleNode("Rang") == null ? "" : xNode.SelectSingleNode("Rang").InnerText;

                examDetailObj.ExamId = examId;
                examDetailObj.ExamType = examType;
                examDetailObj.ExamItem = eaxmItem;
                examDetailObj.Report = report;
                examDetailObj.ReportDate = reportDate;
                examDetailObj.Conclusion = conclusion;
                examDetailObj.DetailItem = detailItem;
                examDetailObj.Result = result;
                examDetailObj.Unit = unit;
                examDetailObj.Alert = alert;
                examDetailObj.Rang = rang;

                response.ExamDetailInfoList.Add(examDetailObj);
            }

            return response;
        }
        #endregion

        #region 获取门诊病人缴费记录
        /// <summary>
        /// 获取门诊病人缴费记录
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetClinPayList")]
        public Response4GetClinPayList GetClinPayList(Request4GetClinPayList request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode invoiceNoNode = xmlDoc.CreateElement("InvoiceNo");
            invoiceNoNode.InnerText = request.InvoiceNo;
            root.AppendChild(invoiceNoNode);

            XmlNode hosPayIdNode = xmlDoc.CreateElement("HosPayId");
            hosPayIdNode.InnerText = request.HosPayId;
            root.AppendChild(hosPayIdNode);

            XmlNode startDateNode = xmlDoc.CreateElement("StartDate");
            startDateNode.InnerText = request.StartDate;
            root.AppendChild(startDateNode);

            XmlNode endDateNode = xmlDoc.CreateElement("EndDate");
            endDateNode.InnerText = request.EndDate;
            root.AppendChild(endDateNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetClinPayList(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetClinPayList 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetClinPayList", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetClinPayList();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ClinPayList = new List<Response4GetClinPayListSubClinPay>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var clinPayObj = new Response4GetClinPayListSubClinPay();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var hosPayId = xNode.SelectSingleNode("HosPayId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPayId".ToUpper()).InnerText;
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var clinNo = xNode.SelectSingleNode("ClinNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("ClinNo".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;
                var cardNo = xNode.SelectSingleNode("CardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("CardNo".ToUpper()).InnerText;
                var patName = xNode.SelectSingleNode("PatName".ToUpper()) == null ? "" : xNode.SelectSingleNode("PatName".ToUpper()).InnerText;
                var payType = xNode.SelectSingleNode("PayType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayType".ToUpper()).InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("TotalAmt".ToUpper()).InnerText;
                var selfAmt = xNode.SelectSingleNode("SelfAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("SelfAmt".ToUpper()).InnerText;
                var sbPayAmt = xNode.SelectSingleNode("SbPayAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("SbPayAmt".ToUpper()).InnerText;
                var payDate = xNode.SelectSingleNode("PayDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayDate".ToUpper()).InnerText;
                var invoiceNo = xNode.SelectSingleNode("InvoiceNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("InvoiceNo".ToUpper()).InnerText;
                var deptId = xNode.SelectSingleNode("DeptId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptId".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var docId = xNode.SelectSingleNode("DocId".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocId".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var cashierId = xNode.SelectSingleNode("CashierId".ToUpper()) == null ? "" : xNode.SelectSingleNode("CashierId".ToUpper()).InnerText;
                var invoicePrinted = xNode.SelectSingleNode("InvoicePrinted".ToUpper()) == null ? "" : xNode.SelectSingleNode("InvoicePrinted".ToUpper()).InnerText;


                clinPayObj.FlowNo = flowNo;
                clinPayObj.HosPayId = hosPatId;
                clinPayObj.HosPatId = hosPatId;
                clinPayObj.ClinNo = clinNo;
                clinPayObj.IdCard = idCard;
                clinPayObj.CardNo = cardNo;
                clinPayObj.PatName = patName;
                clinPayObj.PayType = payType;
                clinPayObj.TotalAmt = totalAmt;
                clinPayObj.SelfAmt = selfAmt;
                clinPayObj.SbPayAmt = sbPayAmt;
                clinPayObj.PayDate = payDate;
                clinPayObj.InvoiceNo = invoiceNo;
                clinPayObj.DeptId = deptId;
                clinPayObj.DeptName = deptName;
                clinPayObj.DoctorId = docId;
                clinPayObj.DoctorName = docName;
                clinPayObj.CashierId = cashierId;
                clinPayObj.InvoicePrinted = invoicePrinted;

                response.ClinPayList.Add(clinPayObj);
            }

            return response;
        }
        #endregion

        #region 获取门诊病人缴费明细
        /// <summary>
        /// 获取门诊病人缴费明细
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetClinPayDetail")]
        public Response4GetClinPayDetail GetClinPayDetail(Request4GetClinPayDetail request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPayIdNode = xmlDoc.CreateElement("HosPayId");
            hosPayIdNode.InnerText = request.HosPayId;
            root.AppendChild(hosPayIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetClinPayDetail(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetClinPayDetail 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetClinPayDetail", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetClinPayDetail();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ClinPayDetailList = new List<Response4GetClinPayDetailSubClinPayDetail>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var clinPayDetailObj = new Response4GetClinPayDetailSubClinPayDetail();

                var hosPayId = xNode.SelectSingleNode("HosPayId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPayId".ToUpper()).InnerText;
                var recipeId = xNode.SelectSingleNode("RecipeId".ToUpper()) == null ? "" : xNode.SelectSingleNode("RecipeId".ToUpper()).InnerText;
                var feeName = xNode.SelectSingleNode("FeeName".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeName".ToUpper()).InnerText;
                var feeCode = xNode.SelectSingleNode("FeeCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeCode".ToUpper()).InnerText;
                var unit = xNode.SelectSingleNode("Unit".ToUpper()) == null ? "" : xNode.SelectSingleNode("Unit".ToUpper()).InnerText;
                var spec = xNode.SelectSingleNode("Spec".ToUpper()) == null ? "" : xNode.SelectSingleNode("Spec".ToUpper()).InnerText;
                var price = xNode.SelectSingleNode("Price".ToUpper()) == null ? "" : xNode.SelectSingleNode("Price".ToUpper()).InnerText;
                var qty = xNode.SelectSingleNode("Qty".ToUpper()) == null ? "" : xNode.SelectSingleNode("Qty".ToUpper()).InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("TotalAmt".ToUpper()).InnerText;
                var selfAmt = xNode.SelectSingleNode("SelfAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("SelfAmt".ToUpper()).InnerText;
                var feeType = xNode.SelectSingleNode("FeeType".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeType".ToUpper()).InnerText;
                var remark = xNode.SelectSingleNode("Remark".ToUpper()) == null ? "" : xNode.SelectSingleNode("Remark".ToUpper()).InnerText;

                clinPayDetailObj.HosPayId = hosPayId;
                clinPayDetailObj.RecipeId = recipeId;
                clinPayDetailObj.FeeName = feeName;
                clinPayDetailObj.FeeCode = feeCode;
                clinPayDetailObj.Unit = unit;
                clinPayDetailObj.Spec = spec;
                clinPayDetailObj.Price = price;
                clinPayDetailObj.Qty = qty;
                clinPayDetailObj.TotalAmt = totalAmt;
                clinPayDetailObj.SelfAmt = selfAmt;
                clinPayDetailObj.FeeType = feeType;
                clinPayDetailObj.Remark = remark;

                response.ClinPayDetailList.Add(clinPayDetailObj);
            }

            return response;
        }
        #endregion

        #region 获取门诊病人缴费分类金额
        /// <summary>
        /// 获取门诊病人缴费分类金额
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetClinPayAmt")]
        public Response4GetClinPayAmt GetClinPayAmt(Request4GetClinPayAmt request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPayIdNode = xmlDoc.CreateElement("HosPayId");
            hosPayIdNode.InnerText = request.HosPayId;
            root.AppendChild(hosPayIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetClinPayAmt(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetClinPayAmt 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetClinPayAmt", requestXml, responseXml);


            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetClinPayAmt();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ClinPayAmtList = new List<Response4GetClinPayAmtSubClinPayAmt>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var clinPayAmtObj = new Response4GetClinPayAmtSubClinPayAmt();

                var feeType = xNode.SelectSingleNode("FeeType").InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt").InnerText;
                var selfAmt = xNode.SelectSingleNode("SelfAmt").InnerText;

                clinPayAmtObj.FeeType = feeType;
                clinPayAmtObj.TotalAmt = totalAmt;
                clinPayAmtObj.SelfAmt = selfAmt;

                response.ClinPayAmtList.Add(clinPayAmtObj);
            }

            return response;
        }
        #endregion

        #region 获取住院号是否有效(只能查询在院患者)
        /// <summary>
        /// 获取住院号是否有效(只能查询在院患者)
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetZyhValid")]
        public Response4GetZyhValid GetZyhValid(Request4GetZyhValid request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode wardNoNode = xmlDoc.CreateElement("WardNo");
            wardNoNode.InnerText = request.WardNo;
            root.AppendChild(wardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetZyhValid(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetZyhValid 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetZyhValid", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetZyhValid();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.FlowNo =
                xmlDoc.SelectSingleNode("/Response/ResultData/" + "FlowNo") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "FlowNo").InnerText;

            return response;
        }
        #endregion

        #region 获取住院病人缴费记录
        /// <summary>
        /// 获取住院病人缴费记录,可以只返回最后一次住院记录
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetWardRecord")]
        public Response4GetWardRecord GetWardRecord(Request4GetWardRecord request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode wardNoNode = xmlDoc.CreateElement("WardNo");
            wardNoNode.InnerText = request.WardNo;
            root.AppendChild(wardNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetWardRecord(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetWardRecord 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetWardRecord", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetWardRecord();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.WardRecordList = new List<Response4GetWardRecordSubWardRecord>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var wardRecordObj = new Response4GetWardRecordSubWardRecord();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var wardNo = xNode.SelectSingleNode("WardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("WardNo".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;

                var name = xNode.SelectSingleNode("Name".ToUpper()) == null ? "" : xNode.SelectSingleNode("Name".ToUpper()).InnerText;
                var sex = xNode.SelectSingleNode("Sex".ToUpper()) == null ? "" : xNode.SelectSingleNode("Sex".ToUpper()).InnerText;
                var birthDay = xNode.SelectSingleNode("BirthDay".ToUpper()) == null ? "" : xNode.SelectSingleNode("BirthDay".ToUpper()).InnerText;
                var inDate = xNode.SelectSingleNode("InDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("InDate".ToUpper()).InnerText;
                var outDate = xNode.SelectSingleNode("OutDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("OutDate".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var nurseDeptName = xNode.SelectSingleNode("NurseDeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("NurseDeptName".ToUpper()).InnerText;
                var dayCount = xNode.SelectSingleNode("DayCount".ToUpper()) == null ? "" : xNode.SelectSingleNode("DayCount".ToUpper()).InnerText;
                var bed = xNode.SelectSingleNode("Bed".ToUpper()) == null ? "" : xNode.SelectSingleNode("Bed".ToUpper()).InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("TotalAmt".ToUpper()).InnerText;
                var depositAmt = xNode.SelectSingleNode("DepositAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("DepositAmt".ToUpper()).InnerText;
                var availableAmt = xNode.SelectSingleNode("AvailableAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("AvailableAmt".ToUpper()).InnerText;
                var payTime = xNode.SelectSingleNode("PayTime".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayTime".ToUpper()).InnerText;
                var payType = xNode.SelectSingleNode("PayType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayType".ToUpper()).InnerText;


                wardRecordObj.FlowNo = flowNo;
                wardRecordObj.HosPatId = hosPatId;
                wardRecordObj.WardNo = wardNo;
                wardRecordObj.IdCard = idCard;
                wardRecordObj.Name = name;
                wardRecordObj.Sex = sex;
                wardRecordObj.BirthDay = birthDay;
                wardRecordObj.InDate = inDate;
                wardRecordObj.OutDate = outDate;
                wardRecordObj.DeptName = deptName;
                wardRecordObj.NurseDeptName = nurseDeptName;
                wardRecordObj.DayCount = dayCount;
                wardRecordObj.Bed = bed;
                wardRecordObj.TotalAmt = totalAmt;
                wardRecordObj.DepositAmt = depositAmt;
                wardRecordObj.AvailableAmt = availableAmt;
                wardRecordObj.PayTime = payTime;
                wardRecordObj.PayType = payType;

                response.WardRecordList.Add(wardRecordObj);
            }

            return response;
        }
        #endregion

        #region 获取住院病人缴费明细
        /// <summary>
        /// 获取住院病人缴费明细
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetWardFeeDetail")]
        public Response4GetWardFeeDetail GetWardFeeDetail(Request4GetWardFeeDetail request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            XmlNode startTimeNode = xmlDoc.CreateElement("StartTime");
            startTimeNode.InnerText = request.StartTime;
            root.AppendChild(startTimeNode);

            XmlNode endTimeNode = xmlDoc.CreateElement("EndTime");
            endTimeNode.InnerText = request.EndTime;
            root.AppendChild(endTimeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetWardFeeDetail(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetWardFeeDetail 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetWardFeeDetail", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetWardFeeDetail();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.WardFeeDetailList = new List<Response4GetWardFeeDetailSubWardFeeDetail>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var wardFeeDetailObj = new Response4GetWardFeeDetailSubWardFeeDetail();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var feeType = xNode.SelectSingleNode("FeeType".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeType".ToUpper()).InnerText;
                var feeName = xNode.SelectSingleNode("FeeName".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeName".ToUpper()).InnerText;
                var feeCode = xNode.SelectSingleNode("FeeCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeCode".ToUpper()).InnerText;
                var unit = xNode.SelectSingleNode("Unit".ToUpper()) == null ? "" : xNode.SelectSingleNode("Unit".ToUpper()).InnerText;
                var spec = xNode.SelectSingleNode("Spec".ToUpper()) == null ? "" : xNode.SelectSingleNode("Spec".ToUpper()).InnerText;
                var price = xNode.SelectSingleNode("Price".ToUpper()) == null ? "" : xNode.SelectSingleNode("Price".ToUpper()).InnerText;
                var qty = xNode.SelectSingleNode("Qty".ToUpper()) == null ? "" : xNode.SelectSingleNode("Qty".ToUpper()).InnerText;
                var amt = xNode.SelectSingleNode("Amt".ToUpper()) == null ? "" : xNode.SelectSingleNode("Amt".ToUpper()).InnerText;
                var billDate = xNode.SelectSingleNode("BillDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("BillDate".ToUpper()).InnerText;
                var feeState = xNode.SelectSingleNode("FeeState".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeState".ToUpper()).InnerText;

                wardFeeDetailObj.FlowNo = flowNo;
                wardFeeDetailObj.FeeType = feeType;
                wardFeeDetailObj.FeeName = feeName;
                wardFeeDetailObj.FeeCode = feeCode;
                wardFeeDetailObj.Unit = unit;
                wardFeeDetailObj.Spec = spec;
                wardFeeDetailObj.Price = price;
                wardFeeDetailObj.Qty = qty;
                wardFeeDetailObj.Amt = amt;
                wardFeeDetailObj.BillDate = billDate;
                wardFeeDetailObj.FeeState = feeState;

                response.WardFeeDetailList.Add(wardFeeDetailObj);
            }

            return response;
        }
        #endregion

        #region 获取住院病人缴费分类金额
        /// <summary>
        /// 获取住院病人缴费分类金额
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetWardAmt")]
        public Response4GetWardAmt GetWardAmt(Request4GetWardAmt request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetWardAmt(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetWardAmt 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetWardAmt", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetWardAmt();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.WardAmtList = new List<Response4GetWardAmtSubWardAmt>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var wardAmtObj = new Response4GetWardAmtSubWardAmt();

                var feeType = xNode.SelectSingleNode("FeeType".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeType".ToUpper()).InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("TotalAmt".ToUpper()).InnerText;
                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;

                wardAmtObj.FlowNo = flowNo;
                wardAmtObj.FeeType = feeType;
                wardAmtObj.TotalAmt = totalAmt;

                response.WardAmtList.Add(wardAmtObj);
            }

            return response;
        }
        #endregion

        #region 获取住院病人预交金
        /// <summary>
        /// 获取住院病人预交金
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetWardDeposit")]
        public Response4GetWardDeposit GetWardDeposit(Request4GetWardDeposit request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetWardDeposit(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetWardDeposit 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }


            HospWsLogHelper.Log("DXGetWardDeposit", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetWardDeposit();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.WardDepositList = new List<Response4GetWardDepositSubWardDeposit>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var wardDepositObj = new Response4GetWardDepositSubWardDeposit();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var depositNo = xNode.SelectSingleNode("DepositNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("DepositNo".ToUpper()).InnerText;
                var payDate = xNode.SelectSingleNode("PayDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayDate".ToUpper()).InnerText;
                var amt = xNode.SelectSingleNode("Amt".ToUpper()) == null ? "" : xNode.SelectSingleNode("Amt".ToUpper()).InnerText;
                var state = xNode.SelectSingleNode("State".ToUpper()) == null ? "" : xNode.SelectSingleNode("State".ToUpper()).InnerText;

                wardDepositObj.FlowNo = flowNo;
                wardDepositObj.DepositNo = depositNo;
                wardDepositObj.PayDate = payDate;
                wardDepositObj.Amt = amt;
                wardDepositObj.State = state;

                response.WardDepositList.Add(wardDepositObj);
            }

            return response;
        }
        #endregion

        #region 获取欠费患者列表
        /// <summary>
        /// 获取欠费患者列表
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetFeeQf")]
        public Response4GetFeeQf GetFeeQf(Request4GetFeeQf request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");
            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetFeeQf();
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetFeeQf 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetFeeQf", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetFeeQf();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.FeeQfList = new List<Response4GetFeeQfSubFeeQf>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var feeQfObj = new Response4GetFeeQfSubFeeQf();

                var cardNo = xNode.SelectSingleNode("PATIENT_NO") == null ? "" : xNode.SelectSingleNode("PATIENT_NO").InnerText;
                var freeCost = xNode.SelectSingleNode("FREE_COST") == null ? "" : xNode.SelectSingleNode("FREE_COST").InnerText;
                var inpatientNo = xNode.SelectSingleNode("INPATIENT_NO") == null ? "" : xNode.SelectSingleNode("INPATIENT_NO").InnerText;
                var inDate = xNode.SelectSingleNode("IN_DATE") == null ? "" : xNode.SelectSingleNode("IN_DATE").InnerText;

                feeQfObj.CardNo = cardNo;
                feeQfObj.FreeCost = freeCost;
                feeQfObj.InpatientNo = inpatientNo;
                feeQfObj.InDate = inDate;

                response.FeeQfList.Add(feeQfObj);
            }

            return response;
        }
        #endregion

        #region 住院预交金支付
        /// <summary>
        /// 住院预交金支付
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("SetWardPreplay")]
        public Response4SetWardPreplay SetWardPreplay(Request4SetWardPreplay request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("WardNo");
            flowNoNode.InnerText = request.WardNo;
            root.AppendChild(flowNoNode);

            XmlNode preCostNode = xmlDoc.CreateElement("PreCost");
            preCostNode.InnerText = request.PreCost;
            root.AppendChild(preCostNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXSetPreplay(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXSetPreplay 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXSetPreplay", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4SetWardPreplay();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            return response;
        }
        #endregion

        #region 获取住院科室病人缴费日记录
        /// <summary>
        /// 获取住院科室病人缴费日记录
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetWardDayAmt")]
        public Response4GetWardDayAmt GetWardDayAmt(Request4GetWardDayAmt request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
            flowNoNode.InnerText = request.FlowNo;
            root.AppendChild(flowNoNode);

            XmlNode startTimeNode = xmlDoc.CreateElement("StartTime");
            startTimeNode.InnerText = request.StartTime;
            root.AppendChild(startTimeNode);

            XmlNode endTimeNode = xmlDoc.CreateElement("EndTime");
            endTimeNode.InnerText = request.EndTime;
            root.AppendChild(endTimeNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetWardDayAmt(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetWardDayAmt 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetWardDayAmt", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetWardDayAmt();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.WardDayAmtList = new List<Response4GetWardDayAmtSubWardDayAmt>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var wardDayAmtObj = new Response4GetWardDayAmtSubWardDayAmt();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var nurseDeptName = xNode.SelectSingleNode("NurseDeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("NurseDeptName".ToUpper()).InnerText;
                var bed = xNode.SelectSingleNode("Bed".ToUpper()) == null ? "" : xNode.SelectSingleNode("Bed".ToUpper()).InnerText;
                var amt = xNode.SelectSingleNode("Amt".ToUpper()) == null ? "" : xNode.SelectSingleNode("Amt".ToUpper()).InnerText;
                var billDate = xNode.SelectSingleNode("BillDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("BillDate".ToUpper()).InnerText;

                wardDayAmtObj.FlowNo = flowNo;
                wardDayAmtObj.DeptName = deptName;
                wardDayAmtObj.NurseDeptName = nurseDeptName;
                wardDayAmtObj.Bed = bed;
                wardDayAmtObj.Amt = amt;
                wardDayAmtObj.BillDate = billDate;

                response.WardDayAmtList.Add(wardDayAmtObj);
            }

            return response;
        }
        #endregion

        #region 获取病人未缴费的处方信息
        /// <summary>
        /// 获取病人未缴费的处方信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetClinRecipes")]
        public Response4GetClinRecipes GetClinRecipes(Request4GetClinRecipes request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode dayCountNode = xmlDoc.CreateElement("DayCount");
            dayCountNode.InnerText = request.DayCount;
            root.AppendChild(dayCountNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetClinRecipes(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetClinRecipes 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetClinRecipes", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetClinRecipes();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ClinRecipeList = new List<Response4GetClinRecipesSubClinRecipe>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var clinRecipeObj = new Response4GetClinRecipesSubClinRecipe();

                var recipeId = xNode.SelectSingleNode("RecipeId".ToUpper()) == null ? "" : xNode.SelectSingleNode("RecipeId".ToUpper()).InnerText;
                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var hosPatId = xNode.SelectSingleNode("HosPatId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPatId".ToUpper()).InnerText;
                var clinNo = xNode.SelectSingleNode("ClinNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("ClinNo".ToUpper()).InnerText;
                var idCard = xNode.SelectSingleNode("IDCard".ToUpper()) == null ? "" : xNode.SelectSingleNode("IDCard".ToUpper()).InnerText;
                var cardNo = xNode.SelectSingleNode("CardNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("CardNo".ToUpper()).InnerText;
                var patName = xNode.SelectSingleNode("PatName".ToUpper()) == null ? "" : xNode.SelectSingleNode("PatName".ToUpper()).InnerText;
                var cureDate = xNode.SelectSingleNode("CureDate".ToUpper()) == null ? "" : xNode.SelectSingleNode("CureDate".ToUpper()).InnerText;
                var deptHisCode = xNode.SelectSingleNode("DeptHisCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptHisCode".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var docHisCode = xNode.SelectSingleNode("DocHisCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocHisCode".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var payType = xNode.SelectSingleNode("PayType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayType".ToUpper()).InnerText;
                var recipeType = xNode.SelectSingleNode("RecipeType".ToUpper()) == null ? "" : xNode.SelectSingleNode("RecipeType".ToUpper()).InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("TotalAmt".ToUpper()).InnerText;

                clinRecipeObj.RecipeId = recipeId;
                clinRecipeObj.FlowNo = flowNo;
                clinRecipeObj.HosPatId = hosPatId;
                clinRecipeObj.ClinNo = clinNo;
                clinRecipeObj.IdCard = idCard;
                clinRecipeObj.CardNo = cardNo;
                clinRecipeObj.PatName = patName;
                clinRecipeObj.CureDate = cureDate;
                clinRecipeObj.DeptHisCode = deptHisCode;
                clinRecipeObj.DeptName = deptName;
                clinRecipeObj.DocHisCode = docHisCode;
                clinRecipeObj.DocName = docName;
                clinRecipeObj.PayType = payType;
                clinRecipeObj.RecipeType = recipeType;
                clinRecipeObj.TotalAmt = totalAmt;

                response.ClinRecipeList.Add(clinRecipeObj);
            }

            return response;
        }
        #endregion

        #region 获取处方明细
        /// <summary>
        /// 获取处方明细
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetClinRecipeDetail")]
        public Response4GetClinRecipeDetail GetClinRecipeDetail(Request4GetClinRecipeDetail request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode recipeIdNode = xmlDoc.CreateElement("RecipeId");
            recipeIdNode.InnerText = request.RecipeId;
            root.AppendChild(recipeIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetClinRecipeDetail(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetClinRecipeDetail 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetClinRecipeDetail", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetClinRecipeDetail();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ClinRecipeDetailList = new List<Response4GetClinRecipeDetailSubClinRecipeDetail>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var clinRecipeDetailObj = new Response4GetClinRecipeDetailSubClinRecipeDetail();

                var recipeId = xNode.SelectSingleNode("RecipeId".ToUpper()) == null ? "" : xNode.SelectSingleNode("RecipeId".ToUpper()).InnerText;
                var feeName = xNode.SelectSingleNode("FeeName".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeName".ToUpper()).InnerText;
                var feeCode = xNode.SelectSingleNode("FeeCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeCode".ToUpper()).InnerText;
                var unit = xNode.SelectSingleNode("Unit".ToUpper()) == null ? "" : xNode.SelectSingleNode("Unit".ToUpper()).InnerText;
                var spec = xNode.SelectSingleNode("Spec".ToUpper()) == null ? "" : xNode.SelectSingleNode("Spec".ToUpper()).InnerText;
                var price = xNode.SelectSingleNode("Price".ToUpper()) == null ? "" : xNode.SelectSingleNode("Price".ToUpper()).InnerText;
                var qty = xNode.SelectSingleNode("Qty".ToUpper()) == null ? "" : xNode.SelectSingleNode("Qty".ToUpper()).InnerText;
                var amt = xNode.SelectSingleNode("Amt".ToUpper()) == null ? "" : xNode.SelectSingleNode("Amt".ToUpper()).InnerText;
                var sort = xNode.SelectSingleNode("Sort".ToUpper()) == null ? "" : xNode.SelectSingleNode("Sort".ToUpper()).InnerText;
                var remark = xNode.SelectSingleNode("Remark".ToUpper()) == null ? "" : xNode.SelectSingleNode("Remark".ToUpper()).InnerText;

                clinRecipeDetailObj.RecipeId = recipeId;
                clinRecipeDetailObj.FeeName = feeName;
                clinRecipeDetailObj.FeeCode = feeCode;
                clinRecipeDetailObj.Unit = unit;
                clinRecipeDetailObj.Spec = spec;
                clinRecipeDetailObj.Price = price;
                clinRecipeDetailObj.Qty = qty;
                clinRecipeDetailObj.Amt = amt;
                clinRecipeDetailObj.Sort = sort;
                clinRecipeDetailObj.Remark = remark;

                response.ClinRecipeDetailList.Add(clinRecipeDetailObj);
            }

            return response;
        }
        #endregion

        #region 预结算处理获得支付金额
        /// <summary>
        /// 预结算处理获得支付金额
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("ClinPayPrepare")]
        public Response4ClinPayPrepare ClinPayPrepare(Request4ClinPayPrepare request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode recipeIdsNode = xmlDoc.CreateElement("RecipeIds");
            recipeIdsNode.InnerText = request.RecipeIds;
            root.AppendChild(recipeIdsNode);

            XmlNode cashierIdNode = xmlDoc.CreateElement("CashierId");
            cashierIdNode.InnerText = request.CashierId;
            root.AppendChild(cashierIdNode);

            XmlNode machineIdNode = xmlDoc.CreateElement("MachineId");
            machineIdNode.InnerText = request.MachineId;
            root.AppendChild(machineIdNode);

            XmlNode isSbNode = xmlDoc.CreateElement("IsSb");
            isSbNode.InnerText = request.IsSb;
            root.AppendChild(isSbNode);

            foreach (var recipeIdInfo in request.Request4ClinPayPrepareSubRecipeIdInfoList)
            {
                XmlNode resultDataNode = xmlDoc.CreateElement("ResultData");

                XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
                flowNoNode.InnerText = recipeIdInfo.FlowNo;
                resultDataNode.AppendChild(flowNoNode);

                XmlNode recipeIdNode = xmlDoc.CreateElement("RecipeId");
                recipeIdNode.InnerText = recipeIdInfo.RecipeId;
                resultDataNode.AppendChild(recipeIdNode);

                XmlNode payTypeNode = xmlDoc.CreateElement("PayType");
                payTypeNode.InnerText = recipeIdInfo.PayType;
                resultDataNode.AppendChild(payTypeNode);

                root.AppendChild(resultDataNode);
            }

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXClinPayPrepare18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXClinPayPrepare18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXClinPayPrepare18", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4ClinPayPrepare();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.ClinPayPrepareList = new List<Response4GetClinPayPrepareSubClinPayPrepare>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var clinPayPrepareObj = new Response4GetClinPayPrepareSubClinPayPrepare();

                var flowNo = xNode.SelectSingleNode("FlowNo".ToUpper()) == null ? "" : xNode.SelectSingleNode("FlowNo".ToUpper()).InnerText;
                var patName = xNode.SelectSingleNode("PatName".ToUpper()) == null ? "" : xNode.SelectSingleNode("PatName".ToUpper()).InnerText;
                var deptHisCode = xNode.SelectSingleNode("DeptHisCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptHisCode".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var docHisCode = xNode.SelectSingleNode("DocHisCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocHisCode".ToUpper()).InnerText;
                var docName = xNode.SelectSingleNode("DocName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DocName".ToUpper()).InnerText;
                var recipeId = xNode.SelectSingleNode("RecipeId".ToUpper()) == null ? "" : xNode.SelectSingleNode("RecipeId".ToUpper()).InnerText;
                var payType = xNode.SelectSingleNode("PayType".ToUpper()) == null ? "" : xNode.SelectSingleNode("PayType".ToUpper()).InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("TotalAmt".ToUpper()).InnerText;
                var selfAmt = xNode.SelectSingleNode("SelfAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("SelfAmt".ToUpper()).InnerText;
                var sbPayAmt = xNode.SelectSingleNode("SbPayAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("SbPayAmt".ToUpper()).InnerText;

                clinPayPrepareObj.FlowNo = flowNo;
                clinPayPrepareObj.PatName = patName;
                clinPayPrepareObj.DeptHisCode = deptHisCode;
                clinPayPrepareObj.DeptName = deptName;
                clinPayPrepareObj.DocHisCode = docHisCode;
                clinPayPrepareObj.DocName = docName;
                clinPayPrepareObj.RecipeId = recipeId;
                clinPayPrepareObj.PayType = payType;
                clinPayPrepareObj.TotalAmt = totalAmt;
                clinPayPrepareObj.SelfAmt = selfAmt;
                clinPayPrepareObj.SbPayAmt = sbPayAmt;

                response.ClinPayPrepareList.Add(clinPayPrepareObj);
            }

            return response;
        }
        #endregion

        #region 交易成功后收费处理
        /// <summary>
        /// 交易成功后收费处理
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("ClinPayFinish")]
        public Response4ClinPayFinish ClinPayFinish(Request4ClinPayFinish request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            XmlNode clinNoNode = xmlDoc.CreateElement("ClinNo");
            clinNoNode.InnerText = request.ClinNo;
            root.AppendChild(clinNoNode);

            XmlNode idCardNode = xmlDoc.CreateElement("IDCard");
            idCardNode.InnerText = request.IdCard;
            root.AppendChild(idCardNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("CardNo");
            cardNoNode.InnerText = request.CardNo;
            root.AppendChild(cardNoNode);

            XmlNode recipeIdsNode = xmlDoc.CreateElement("RecipeIds");
            recipeIdsNode.InnerText = request.RecipeIds;
            root.AppendChild(recipeIdsNode);

            XmlNode payAmtNode = xmlDoc.CreateElement("PayAmt");
            payAmtNode.InnerText = request.PayAmt;
            root.AppendChild(payAmtNode);

            XmlNode bankCardNoNode = xmlDoc.CreateElement("BankCardNo");
            bankCardNoNode.InnerText = request.BankCardNo;
            root.AppendChild(bankCardNoNode);

            XmlNode payDateNode = xmlDoc.CreateElement("PayDate");
            payDateNode.InnerText = request.PayDate;
            root.AppendChild(payDateNode);

            XmlNode cashierIdNode = xmlDoc.CreateElement("CashierId");
            cashierIdNode.InnerText = request.CashierId;
            root.AppendChild(cashierIdNode);

            XmlNode machineIdNode = xmlDoc.CreateElement("MachineId");
            machineIdNode.InnerText = request.MachineId;
            root.AppendChild(machineIdNode);

            XmlNode resultDataNode = xmlDoc.CreateElement("ResultData");
            foreach (var recipeIdInfo in request.Request4ClinPayFinishSubRecipeIdInfoList)
            {
                XmlNode flowNoNode = xmlDoc.CreateElement("FlowNo");
                flowNoNode.InnerText = recipeIdInfo.FlowNo;
                resultDataNode.AppendChild(flowNoNode);

                XmlNode recipeIdNode = xmlDoc.CreateElement("RecipeId");
                recipeIdNode.InnerText = recipeIdInfo.RecipeId;
                resultDataNode.AppendChild(recipeIdNode);

                XmlNode payTypeNode = xmlDoc.CreateElement("PayType");
                payTypeNode.InnerText = recipeIdInfo.PayType;
                resultDataNode.AppendChild(payTypeNode);

                XmlNode totalAmtNode = xmlDoc.CreateElement("TotalAmt");
                totalAmtNode.InnerText = recipeIdInfo.TotalAmt;
                resultDataNode.AppendChild(totalAmtNode);

                XmlNode selfAmtNode = xmlDoc.CreateElement("SelfAmt");
                selfAmtNode.InnerText = recipeIdInfo.SelfAmt;
                resultDataNode.AppendChild(selfAmtNode);

                XmlNode sbPayAmtNode = xmlDoc.CreateElement("SbPayAmt");
                sbPayAmtNode.InnerText = recipeIdInfo.SbPayAmt;
                resultDataNode.AppendChild(sbPayAmtNode);
            }
            root.AppendChild(resultDataNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXClinPayFinish18(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXClinPayFinish18 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXClinPayFinish18", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4ClinPayFinish();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.HosPayId = xmlDoc.SelectSingleNode("/Response/ResultData/" + "HosPayId") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "HosPayId").InnerText;
            response.RecipeIds = xmlDoc.SelectSingleNode("/Response/ResultData/" + "RecipeIds") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "RecipeIds").InnerText;
            response.InvoiceNo = xmlDoc.SelectSingleNode("/Response/ResultData/" + "InvoiceNo") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "InvoiceNo").InnerText;
            response.TotalAmt = xmlDoc.SelectSingleNode("/Response/ResultData/" + "TotalAmt") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "TotalAmt").InnerText;
            response.SelfAmt = xmlDoc.SelectSingleNode("/Response/ResultData/" + "SelfAmt") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "SelfAmt").InnerText;
            response.SbPayAmt = xmlDoc.SelectSingleNode("/Response/ResultData/" + "SbPayAmt") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "SbPayAmt").InnerText;
            response.ResultMark = xmlDoc.SelectSingleNode("/Response/ResultData/" + "ResultMark") == null ? "" : xmlDoc.SelectSingleNode("/Response/ResultData/" + "ResultMark").InnerText;

            response.ResultDataList = new List<Response4GetClinPayFinishSubResultData>();
            var resultDataNodes = xmlDoc.SelectNodes("/Response/ResultDataList");
            foreach (XmlNode xNode in resultDataNodes)
            {
                var clinPayFinishResultDataObj = new Response4GetClinPayFinishSubResultData();

                var hosPayId = xNode.SelectSingleNode("HosPayId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPayId".ToUpper()).InnerText;
                var feeType = xNode.SelectSingleNode("FeeType".ToUpper()) == null ? "" : xNode.SelectSingleNode("FeeType".ToUpper()).InnerText;
                var totalAmt = xNode.SelectSingleNode("TotalAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("TotalAmt".ToUpper()).InnerText;
                var selfAmt = xNode.SelectSingleNode("SelfAmt".ToUpper()) == null ? "" : xNode.SelectSingleNode("SelfAmt".ToUpper()).InnerText;

                clinPayFinishResultDataObj.HosPayId = hosPayId;
                clinPayFinishResultDataObj.FeeType = feeType;
                clinPayFinishResultDataObj.TotalAmt = totalAmt;
                clinPayFinishResultDataObj.SelfAmt = selfAmt;

                response.ResultDataList.Add(clinPayFinishResultDataObj);
            }

            response.ExecuteInfoList = new List<Response4GetClinPayFinishSubExecuteInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultDataList");
            foreach (XmlNode xNode in nodes)
            {
                var clinPayFinishExecuteInfoObj = new Response4GetClinPayFinishSubExecuteInfo();

                var hosPayId = xNode.SelectSingleNode("HosPayId".ToUpper()) == null ? "" : xNode.SelectSingleNode("HosPayId".ToUpper()).InnerText;
                var recipeIds = xNode.SelectSingleNode("RecipeIds".ToUpper()) == null ? "" : xNode.SelectSingleNode("RecipeIds".ToUpper()).InnerText;
                var deptHisCode = xNode.SelectSingleNode("DeptHisCode".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptHisCode".ToUpper()).InnerText;
                var deptName = xNode.SelectSingleNode("DeptName".ToUpper()) == null ? "" : xNode.SelectSingleNode("DeptName".ToUpper()).InnerText;
                var execType = xNode.SelectSingleNode("ExecType".ToUpper()) == null ? "" : xNode.SelectSingleNode("ExecType".ToUpper()).InnerText;
                var message = xNode.SelectSingleNode("Message".ToUpper()) == null ? "" : xNode.SelectSingleNode("Message".ToUpper()).InnerText;

                clinPayFinishExecuteInfoObj.HosPayId = hosPayId;
                clinPayFinishExecuteInfoObj.RecipeIds = recipeIds;
                clinPayFinishExecuteInfoObj.DeptHisCode = deptHisCode;
                clinPayFinishExecuteInfoObj.DeptName = deptName;
                clinPayFinishExecuteInfoObj.ExecType = execType;
                clinPayFinishExecuteInfoObj.Message = message;

                response.ExecuteInfoList.Add(clinPayFinishExecuteInfoObj);
            }

            return response;
        }
        #endregion


        #region 获取产妇信息
        /// <summary>
        /// 获取产妇信息
        /// </summary>
        /// <param name="request"></param>
        [HttpPost]
        [ActionName("GetMaternalInfo")]
        public Response4GetMaternalInfo GetMaternalInfo(Request4GetMaternalInfo request)
        {
            var wsClient = WsClientFactory.GetHisWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode IDCardNode = xmlDoc.CreateElement("IDCard");
            IDCardNode.InnerText = request.IDCard;
            root.AppendChild(IDCardNode);

            XmlNode wardNoNode = xmlDoc.CreateElement("WardNo");
            wardNoNode.InnerText = request.WardNo;
            root.AppendChild(wardNoNode);

            XmlNode hosPatIdNode = xmlDoc.CreateElement("HosPatId");
            hosPatIdNode.InnerText = request.HosPatId;
            root.AppendChild(hosPatIdNode);

            xmlDoc.AppendChild(root);

            var requestXml = xmlDoc.InnerXml;

            var responseXml = "";
            try
            {
                responseXml = wsClient.DXGetMaternalInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 DXGetMaternalInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("DXGetMaternalInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new Response4GetMaternalInfo();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.MaternalInfo = new Response4GetMaternalInfoSubMaternalInfo();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            foreach (XmlNode xNode in nodes)
            {
                var doctorInfoObj = new Response4GetMaternalInfoSubMaternalInfo();
                var Name = xNode.SelectSingleNode("Name") == null ? "" : xNode.SelectSingleNode("Name").InnerText;
                var IDCard = xNode.SelectSingleNode("IDCard") == null ? "" : xNode.SelectSingleNode("IDCard").InnerText;
                var CardNo = xNode.SelectSingleNode("CardNo") == null ? "" : xNode.SelectSingleNode("CardNo").InnerText;
                var PregnancyDT = xNode.SelectSingleNode("PregnancyDT") == null ? "" : xNode.SelectSingleNode("PregnancyDT").InnerText;
                var ChildbirthDT = xNode.SelectSingleNode("ChildbirthDT") == null ? "" : xNode.SelectSingleNode("ChildbirthDT").InnerText;
                var Age = xNode.SelectSingleNode("Age") == null ? "" : xNode.SelectSingleNode("Age").InnerText;

                doctorInfoObj.Name = Name;
                doctorInfoObj.IDCard = IDCard;
                doctorInfoObj.CardNo = CardNo;
                doctorInfoObj.PregnancyDT = PregnancyDT;
                doctorInfoObj.ChildbirthDT = ChildbirthDT;
                doctorInfoObj.Age = Age;

                response.MaternalInfo = doctorInfoObj;
            }
            return response;
        }

        #endregion

    }
}